0
I am learning POO in python and am having a problem. When I try to use the getters and setters I am not getting.
#Método Construtor
def __init__(self):
self.saldo = 0
self.status = False
#Métodos Especiais
def getSaldo(self):
return self.saldo
def setDono(self, d):
self.dono = d
#Demais Métodos
def abrirConta(self):
if self.status == False:
a = input('Quem é o titular da conta? ')
setDono(a)
self.tipo = input('Qual é o tipo da conta? ')
self.status = True
if self.tipo == 'CC':
self.saldo = 50
print('Parabéns, sua conta corrente está aberta. Você já tem 50 reais de saldo.')
elif self.tipo == 'CP':
self.saldo = 150
print('Parabéns, sua conta poupança está aberta. Você já tem 150 reais de saldo.')
When I call Setter setDono
in the same document of the class it gives me error, saying that setDono
is not defined. If I call it in another document, as in an instantiated object it works, but the getters return what seems to me to be the location in memory that the data is allocated, rather than what it contains
This error happens because your class does not have this owner attribute set. Try placing the constructor equally to the attribute balance and status.
– Lorenzo Fernandez
I did that, I put it in the self.dono builder and it keeps repeating the error. Some other idea?
– Ferrugem
What was the line that made the mistake? Post it and post the
def
setSaldo also. Check if you have any "decorator" in setSaldo.– Guilherme Nascimento