0
"Making a deposit", help me!
I don't known error for this code. Please explain for me. class BankAccount: def __init__(self, balance): self._balance = balance def __repr__(self): return "Account Balance: {}".format(self._balance) def deposit(self, amount): #your code goes here self.amount = amount return self._balance + self.amount acc = BankAccount(0) acc.deposit(int(input())) print(acc)
6 Respuestas
+ 2
Thank you. It works. Yes, _balance is property, i was confused. But i don't know my code is error. Please explain for me.
+ 1
Is this a challenge? if so, I can't tell you unless I also know the instruction.
Challenges usually requires you to do the exact instruction, no more and no less. So I suggest you to pay extra attention to the requirement, and see if your code gives the exact output as instructed.
0
Try to update account _balance inside deposit() method.
def deposit( self, amount ):
self._balance += amount
If there is anything to be returned, you probably want to return a boolean, indicating whether the deposit process was valid e.g. <amount> is greater than zero.
0
_balance method is private methods
0
_balance is a property, not a method.
I edited my previous response, missed the underscore for <_balance> property name.
0
It's just a practice in the "Python Core" course.