Building Useful Classes 11/11


#1

Looked everywhere, can you help me figure out what is wrong. The error says invalid syntax in line 10.

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)" % (str(self.x, str(self.y), str(self.z))

my_point = Point3D(1, 2, 3) **Line 10
print my_point


#2

Not sure about this line. I reduced it to this, and passed:

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

#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

** Changed what you said, now getting this error.

Traceback (most recent call last):
File "python", line 11, in
File "python", line 8, in repr
TypeError: not all arguments converted during string formatting


#4

Typo. It's the little things that come around and bite us.


#5

Thank youu, thought i checked that many times before


#6

Here is what worked for me. I stayed away from the char '' quotation marks as the repr method apparently is working with strings. Here is my code that worked.

class Point3D(object):
    #initaliser method
    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

#7

What new light can we shed on the opening topic with this post? I don't see any difference, apart fromt he obvious.


#8

Hi,

Why is it return?

I wrote def__ rear__() the same way I wrote def __init __()- how are you supposed to know that repr takes return?


#9

it should be "(%d, %d, %d)" % (self.x, self.y, self.z)
not "(%d, %d, %d)" % (str(self.x, str(self.y), str(self.z))
because %d means integer(base 10) not string


#13