+ 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

1st Jun 2021, 2:02 PM
Egor Tonchev(EGO)
Egor Tonchev(EGO) - avatar
7 Respuestas
+ 8
Lothar ,yours code is better than my. Thank You, too👍
1st Jun 2021, 2:36 PM
Egor Tonchev(EGO)
Egor Tonchev(EGO) - avatar
+ 8
🅰🅹 🅐🅝🅐🅝🅣 ,Your code is better, thanks 👍
1st Jun 2021, 3:55 PM
Egor Tonchev(EGO)
Egor Tonchev(EGO) - avatar
+ 7
Lothar ,it works fine. Thanks 👍
1st Jun 2021, 2:26 PM
Egor Tonchev(EGO)
Egor Tonchev(EGO) - avatar
+ 7
Denise Roßberg ,thanks 👍
1st Jun 2021, 2:37 PM
Egor Tonchev(EGO)
Egor Tonchev(EGO) - avatar
+ 6
your return statement should be: return BankAccount(self.balance+ other.balance) # at the moment you have 2 lines should be one line
1st Jun 2021, 2:12 PM
Lothar
Lothar - avatar
+ 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.
1st Jun 2021, 2:29 PM
Denise Roßberg
Denise Roßberg - avatar
+ 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)
1st Jun 2021, 2:22 PM
A͢J
A͢J - avatar