11/11 Building useful classes


#1

What's wrong with my code? :frowning:

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

my_point = Point3D(1, 2, 3)   


print my_point

Codecademy told me:

Oops, try again. Define a new class by using the class keyword.

Console printed:

Traceback (most recent call last):
  File "python", line 12, in <module>
TypeError: Point3D() takes exactly 1 argument (3 given)

Tks for the help. :slight_smile:


#2

The error wants you to:

Define a new class by using the class keyword.

and now see what you are doing:

def Point3D(object):

pretty self-explanatory :wink:


#3

Sorry. My bad, careless mistake. :blush:


#4

2 posts were split to a new topic: 11/11