11/11 Building useful classes


#1

Hi there,
I've already been checking around for any similar problem...
If I'm a true beginner (so talk slowly, ^ ^ thanks) the solution is certainly for good ones
-bugging navigator?-
I'm confident with this cos most students questions around here got the same code as mine.

Whatever it is and whoever you are, thanks for your solution.

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

   Traceback (most recent call last):  File "python", line 10, in <module>
    TypeError: object.__new__() takes no parameters

#2

From reading your code:
it would appear the errors
are as follows:

_init_ should be __init__
_repr_ should be __repr__

The Completed code Should look something like this

  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)

#4

It's quite embarrassing...

Thanks a lot !