Whats wrong with my code? 11.building useful classes


#1



What should i change in my code? Do those quotes before parentheses causes problem?

https://www.codecademy.com/courses/python-intermediate-en-egNXj/1/5?curriculum_id=4f89dab3d788890003000096#


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


#2

Hi, @sadesoda ,

Check your output very closely. You printed ...

(1,2,3)

... but should have printed ...

(1, 2, 3)

#3

sorry, it doesnt work too


#4

@sadesoda ,

The quotes before the parentheses are not the problem. In fact, they are needed in order to delimit the format string.

The problem is that your format string does not include a space after each of the two commas. You have ...

return "(%d,%d,%d)" % (self.x,self.y,self.z)

This part of the statement is the format string, and is the only thing you need to change ...

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

Without spaces after the commas, the __repr__ method returned ...

(1,2,3)

... instead of ...

(1, 2, 3)

If you put a space after each of the commas in the format string, it will produce the output format specified in the instructions.


#5

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