18. Inheritance Takes no parameters?


#1

I keep on getting this error:

Traceback (most recent call last):
File "python", line 12, in
TypeError: object.new() takes no parameters

even though I've checked it with other codes here. Can anyone tell me what's wrong?

class Triangle(object):
    def _init_(self, angle1, angle2, angle3):
        self.angle1 = angle1
        self.angle2 = angle2
        self.angle3 = angle3
    number_of_sides = 3
    def check_angles(self):
        if self.angle1+self.angle2+self.angle3 == 180:
            return True
        else:
            return False
my_triangle = Triangle(90,30,60)
print my_triangle.number_of_sides
print my_triangle.check_angles()

class Equilateral(Triangle):
    angle = 60
    def _init_(self):
        self.angle1 = angle
        self.angle2 = angle
        self.angle3 = angle

#2

HI first teh init should be like that

def __init__(self):

with two _ before and after then this part

    def __init__(self):
        self.angle1 = angle
        self.angle2 = angle
        self.angle3 = angle

you should put all the self.angle(1,2,3) shoudl be equal to self.angle instead of angle


#3

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