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)

29th Jul 2021, 3:52 AM
David Tom
David Tom - avatar
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.
29th Jul 2021, 4:33 AM
David Tom
David Tom - avatar
+ 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.
29th Jul 2021, 4:38 AM
Ipang
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.
29th Jul 2021, 4:14 AM
Ipang
0
_balance method is private methods
29th Jul 2021, 4:20 AM
David Tom
David Tom - avatar
0
_balance is a property, not a method. I edited my previous response, missed the underscore for <_balance> property name.
29th Jul 2021, 4:27 AM
Ipang
0
It's just a practice in the "Python Core" course.
29th Jul 2021, 4:41 AM
David Tom
David Tom - avatar