18. Inheritance


I'm stuck at the Inheritance exercise in Introduction to Classes.

I'm getting this error:
Failed to instantiate Equilateral, an error was thrown: 'Equilateral' object has no attribute 'angle1'

I have no idea what I'm doing wrong! Help would be appreciated :slight_smile:

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
            return False

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

my_triangle = Triangle(90, 30, 60)
print my_triangle.number_of_sides
print my_triangle.check_angles()


Hi, @cmiya ,

Does the __init__ method of your Equilateral class contain the three assignment statements that you need there? The assignment operator is a single = character.


I got the same result (assignment operator was ok)


Hi, @jocremustech ,

If you post your code, we might be able to identify the problem.


Hi @appylpye ,

Just mentioned the result was the same, I got the solution. Had to read carefully the exercise : -)


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