- This topic has 1 reply, 2 voices, and was last updated 5 years, 5 months ago by .
Viewing 2 posts - 1 through 2 (of 2 total)
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.
Home › Forums › Fórum Interface Gráfica para Apps Python com GTK e Glade › NameError: name ‘calculadora’ is not defined
class calculadora():
def __init__(self):
self.funcoes = {
“soma”: self.soma,
“subtracao”: self.subtracao,
“multiplicacao”: self.multiplicacao,
“divisao”: self.divisao,
“raiz_quadrada”: self.raiz_quadrada,
“porcentagem”: self.porcentagem
}
def soma(self, x, y):
return x + y
def subtracao(self, x, y):
return x – y
def multiplicacao(self, x, y):
return x * y
def divisao(self, x, y):
return x / y
def raiz_quadrada(self, x):
return x ** (1/2)
def porcentagem(self, x, y):
return (x * y) / 100
if __name__ == ‘__main__’:
calculadora = calculadora()
resultado = calculadora.funcoes[‘subtracao’](1, 2)
print(“Resultado: “, resultado)
C:\msys64\mingw64\bin\python3.exe C:/msys64/home/claudio/Projeto3/calculadora.py
Traceback (most recent call last):
File “C:/msys64/home/claudio/Projeto3/calculadora.py”, line 1, in <module>
class calculadora():
File “C:/msys64/home/claudio/Projeto3/calculadora.py”, line 31, in calculadora
calculadora = calculadora()
NameError: name ‘calculadora’ is not defined
Process finished with exit code 1
Olá Claudio,
creio que seja problema de indentação, experimente rever a aula para ver se fez algo diferente, principalmente os espaçamentos.
Segue imagem do código:
