11.building useful classes


#1



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


Traceback (most recent call last):
File "python", line 10, in
NameError: name 'self' is not defined


im not sure what im doing wrong. heeeeeeeeeeeeeelllp


def 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, self.y, self.z))
        
my_point = Point3D(self,1,2,3)

print my_point


#2

HI the instruction aske you ì..
03. Define a __repr__() method that returns "(%d, %d, %d)" % (self.x, self.y, self.z)...

AND

def Point3D(object):

should be

class Point3D(object):

#3

My code then should have been working. Isn't it?

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(1,2,3)

It isn't working :frowning:


#4

Hi this line

print my_point(1,2,3)

remove the (1,2,3) .. my_point is a variable


#5

i hate it when the nswer is so simple thank you:grinning:


#6

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