11/11 Confused :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

this is what I have coded but it told me that " it looks like you didn't print "(1,2,3)". "
what's wrong with my code?hope you can help me ,thx


#2

I have written init and repr it is not the problem ,but it didn't display the right sequence


#4

Notice the spacing between the "%d"s.


#5

print my_point.repr() ,
you shoul let the machine know you my_point object


#6

your answer was a great help to me


#7

Same problem here. Solution is as @tg383893686 described. Mind the gaps.

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) #check the spaces, there is one always
my_point=Point3D(1,2,3)
print my_point

#8

Same problem and solution. I had another one earlier that I was just missing a period. So annoying.


#9

worked, it's spaing problem,TX


#10

Adding ".repr()" to "print my_point" didn't help me. In fact, if I go back and add it on to my code, (which already worked) it will cause an error message.


#11

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


#12

Hi! was with same problem this is the code that showed the error Oops, try again. It looks like you didn't print "(1, 2, 3)".
::
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
Oh ■■■■ no codeacdemy the mistake::
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)") #notice the brackets inside the string.. they passed me.. % (self.x, self.y, self.z)

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


#13

indeed the brackets were the problem