Building useful classes


#1



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


It looks like you didn't print "(1, 2, 3)".


The output is shown. but the error message persists. Tried changing spacing too.


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, @a1301,

Compare your output generated in the return statement to ...

... the following format: (x, y, z) ....

... from the instructions.

Do you really want this entire expression to be a string? ...

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

... and do you have the specified spacing?

The instructions do not have double-quotes included as part of the format, though the message may have left that unclear. While you do need either single or double-quotes to delimit the string, you have double-quotes within the single-quotes, making the double-quotes part of the string. Choose a set of quotes to delimit the string, and leave the other set out.

After addressing that issue, reconsider the spacing of the output.


#3

I have the same problem in two exercise. This one and the 7. Same thing I had my code checked and it still return error. I find it sooo frustrating to have to waist time on syntax of the result. Some thing could be improved here.


#4

I thought there was something link to the usage of string. I tried again and again and arrived to the code in comment, Then I copied the code from the example. They looks exactly the same and the result is the same:

Oops, try again. It looks like you didn't print "(1, 2, 3)".

Code:

"""
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 """

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

Any suggestions?


#5

Hi, @jef.tanguygmail.com ,

The format specified in the instructions is (x, y, z). You seem to be getting "(1,2,3)". It needs to include the proper spacing, and to exclude the extra quotes.


#6

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