Building useful classes


#1

what's the problem with the code:

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

output : "(1,2,3)"

its giving me the error as it looks like you didn't print "(1,2,3)"


#2

sorry...pasted wrong one...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


#3

Well it's not indented. Do you mean something else? If so, what? And if you want others to be able to look at what you've got you've got to make sure it's exactly the same, indentation for example can't be different.


#4

code is working fine and I am getting the result also as expected (x,y,z)
but its giving me warning as It looks like you didn't print "(1, 2, 3)". and i am not
able to proceed to next section


#5

Those are different formats. The second one has spaces in it.


#6

Thanks man...it was space issue only :slight_smile:


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.