0

Why it show attribute error? Help to me fix the code

class a: _egg = 5 def tot(self): print(self._egg) onj = a() onj.tot print(onj._a__egg)

27th Mar 2022, 5:40 AM
Amala Yakin
5 Answers
+ 1
The tot() method (and its body block) is not properly indented, thus it was not recognized as a member of class 'a'
27th Mar 2022, 6:32 AM
Ipang
+ 2
In SoloLearn or not, indentation always works for me though ...
27th Mar 2022, 7:02 AM
Ipang
+ 2
Amala Yakin Indentation always works in Sololearn. A class has attribute _egg not _a_egg class a: _egg = 5 def tot(self): print(self._egg) onj = a() onj.tot() print(onj._egg)
27th Mar 2022, 8:53 AM
AĶ¢J
AĶ¢J - avatar
0
Use egg as variable not _egg
29th Mar 2022, 6:01 AM
PIYUSH
PIYUSH - avatar
- 2
Yeah bro your answer is correct , but in sololearn sometimes indentation not working, that's main reason ...
27th Mar 2022, 7:00 AM
Amala Yakin