11. building useful classes: Bug? invalid syntax error on my variable


#1

invalid syntax error pointing to

my_point = Point3D(1, 2, 3)

whole code here:

class Point3D(object):
def __init__(self, x, y, z):
    self.x = x
    self.y = y
    self.z = z
def __repr__(self):
    return '(%d, %d, %d)' % ((self.x, self.y, self.z)

my_point = Point3D(1, 2, 3)
print my_point

**UPDATE: it must be a bug, I deleted the whole thing and retyped it exactly the same and it worked.... Wouldn't work with copy paste though


#2

There is some problem with your last line of code. The closing paranthesis is missing.

Please find my code:

class Point3D(object):
def init(self,x,y,z):
self.x = x
self.y = y
self.z = z
def repr(self):
return "(%d, %d, %d)" %(self.x,self.y,self.z)
my_point = Point3D(1,2,3)
print my_point


#3

try chang the methods to

def __init__(self, x, y ,z):

and

def __repr__(self):

#4

I had a problem having my code accepted when I didn't put spaces in the string "(%d, %d, %d)"
Just in case that helps anyone.