Coding using classes

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 would like to see the output of print(obj.x,obj.y). However, I keep getting this error:
Traceback (most recent call last):
File “./code_with_class.py”, line 19, in
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 do I improve this code?

Init should be surrounded by two underscores, not one. These special routines are dubbed dunders (double underscored) for that reason.

As mentioned, replace _init_ with __init__

I used the double underscores for init : __init__  then I ran the code again but this time I got this error : 

Traceback (most recent call last):
File “./code_with_class.py”, line 18, in
obj=Child()
TypeError: init() missing 1 required positional argument: ‘x’

I do not quite understand what this means. What do I need to do in this case?

Python is very well documented. In the tutorial part, you will find this here:

“Of course, the __init__() method may have arguments for greater flexibility. In that case, arguments given to the class instantiation operator are passed on to __init__() .”

I got it thank you.

I got it to run thank you.