+ 2
why it getting error?
4 Réponses
+ 8
1:
it's __init__ not _init_
2:
x and y is not defined
use point(1,2) point(x=1, y=2) or
x, y = 1, 2
point(x, y)
3:
you should use self.x not x.self (first_parameter_name.x)
class point:
def __init__(self,x,y):
self.x = x
self.y = y
x, y = 1, 2
p1= point(x,y)
print(p1.x)
+ 1
You have to set values in p1=Point(x,y) or variables,
BTW: __init__ is with 2 leading and trailing underscores:
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
p1 = Point(3,4)
print(p1.x)
+ 1
Here's a correct version of the code.
https://code.sololearn.com/c4L9cj2YuOKZ/?ref=app
+ 1
thanks :)