11 - Building Useful Classes


#1


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


i get the following error with this code, even though it prints the point correctly:
Oops, try again. It looks like you didn't print "(1, 2, 3)".

EDIT: my code is indented correctly, this thing doesnt display the code correctly
UPDATE: prob is solved, it needs spaces between %d and the next comma


#2

class Point3D(object):
def init(self,x,y,z):
self.x = x
self.y = y
self.z = z

def __repr__(self):
    return str("(%d, %d, %d)" % (self.x, self.y, self.z))

my_point = Point3D(1,2,3)

print my_point


#3

You forgot the command STR inside function repr


#4

no it doesnt, didnt you notice the quotes around (%d,%d,%d)?
"(%d,%d,%d)" is already a string. so str("(%d,%d,%d)") is pointless!

And i updated the thread, the prob is solved