Python Code for Class def__add__ with error

Getting error message right after def__add__(self, other): any idea anyone thx!!
def init(self, x, y):
self.x = x
self.y = y
def__add__(self, other): at this point getting error message
return Point(self.x + other.x, self.y + other.y)
point = Point(10, 20)
other = Point(1. 2)
combined = point + other
print(combined.x)

Hello,

Did you create the class in the first line? before/above the init magic method?

When creating the other-object you have a float within the parenthesis, instead of two ints - (1. 2) instead of (1,2).

When I take your code and try it with a comma instead of a point, and creating a PointClass first it works. Hope this helps you.

class Point():
def init(self, x, y):
self.x = x
self.y = y

def add(self, other):
return Point(self.x + other.x, self.y + other.y)

point = Point(10, 20)
other = Point(1, 2)
combined = point + other
print(combined.x)

Well, your code have some logical error, you can try below code once and confirm me weather it is working or not ?

class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __add__(self, other):
        return Point(self.x + other.x, self.y + other.y)

point = Point(10, 20)
other = Point(1, 2)
combined = point + other
print(combined.x)

Thanks

Worked thx!!

Question Mr. Gulshan(like your name)
How do i swith Vscode to Intaeractive terminal, shell it is easy doing in IDLE