11/11 Building useful classes Is this wrong?


#1

Here is 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


the program tells me something is wrong and I am not sure what do differently.

Thank you for your help.


#2

Can you post what exactly program tells you? Without error message it is difficult to figure out what is wrong. Code seems to be correct.


#3

Are you allowed to write init like that??

This works:

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


#4

The problem here is minor. It's just the spacing between the "%d"s. Try replacing

"(%d,%d,%d)"

with

"(%d, %d, %d)"

#5

the 'space' was so difficult to see..... :cry: