
I don't understand why this is wrong, someone please help.
I don't understand why this is wrong, someone please help.
Anything after
return is unreachable. The last two lines above should not be inside the class definition.
my_point is an instance of the class. Remove all indentation on those lines.
Yes, like that. Did you get the expected print out? I'm not sure that the representation is as expected.
return "(%d, %d, %d)" % (self.x, self.y, self.z)
should be enough to satisfy the requirements.
Ok, so I changed the code a bit and managed to figure it out and pass the lesson. Thanks for your help @mtf
The correct code is:
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
sorry I don't know how to format the code correctly so you will have to figure out the indenting yourself!
The names
__init__ and
__repr__ must begin and end with two underscores to be recognized properly.
Formatting your code when you post it would enable users to see your indentation, those important underscores, and other details.
See How do I format code in my posts?.
The below is my code which works.
Please take care of the indentation.
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
look well sintax init in class must have init ect!!!!