#!/usr/bin/python3 class Parent: def _init_(self,x): self.x=x def count(self,x): self.x = self.x + 1 class Child(Parent): def _init_(self, y=0): Parent._init_(self,3) self.y = y def count(self): self.y +=1 obj=Child() obj.count() print(obj.x,obj.y)I am using class in this code and I would like to see what: print(obj.x, obj.y) yields. However, I get this error:
Error:Traceback (most recent call last):
File "./code_with_class.py", line 19, in <module>
obj.count()
File "./code_with_class.py", line 16, in count
self.y +=1
AttributeError: 'Child' object has no attribute 'y'
What do I need to do to correct this? How can I improve this code?
Larz60+ write Oct-27-2020, 04:48 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
I added for you this time, Please use in all future posts.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
I added for you this time, Please use in all future posts.