+ 5
Why it is appeared "self undefined" in line 9?
When I 'm running it it is appeared. https://code.sololearn.com/cx4mMiprTJDj/?ref=app
7 Respuestas
+ 8
Lothar ,yours code is better than my. Thank You, too👍
+ 8
🅰🅹 🅐🅝🅐🅝🅣 ,Your code is better, thanks 👍
+ 7
Lothar ,it works fine. Thanks 👍
+ 7
Denise Roßberg ,thanks 👍
+ 6
your return statement should be:
return BankAccount(self.balance+ other.balance) # at the moment you have 2 lines should be one line
+ 2
https://code.sololearn.com/c08iZokvcnOc/?ref=app
Lothar
Die you notice that there is not an extra space between return and BankAccount(self.balance + other.balance)?
If you remove the space you get returnBank...And if you add the space again you get the correct indentation (see my code).
Maybe more a problem of code playground. Or the code is copied into the playground.
+ 1
Egor Tonchev(EGO)
Change your __add__ method like this
def __add__(self, other):
return (self.balance + other.balance)
----------------
class BankAccount:
def __init__(self, balance):
self.balance = balance
def __add__(self, other):
return (self.balance + other.balance)
a = BankAccount(1024)
b = BankAccount(42)
result = a + b
print(result)