# 18 Inheritance. What does class Equilateral(Triangle) do?

#1

``````My code runs, but what is the point of adding a class Equilateral? How can you make the code print "I am a Equilateral" thanks

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):
#sum_a = angle1 + angle2 + angle3
if self.angle1 + self.angle2 + self.angle3 == 180:
print "triangle"
return True
else:
print "no triangle"
return False
class Equilateral(Triangle):
angle = 60
def __init__(self):
self.angle1 = self.angle
self.angle2 = self.angle
self.angle3 = self.angle

def display_message(self):
print "I am a Equilateral"

my_triangle = Triangle(80,60,60)

print my_triangle.number_of_sides
print my_triangle.check_angles()``````

#2

@cssmaster55309: Well ... there isn't really a need to use inheritance in this example, not a really good one but better than nothing.
The purpose of this exercise is just to show how inheritance works, syntactically speaking.

You'll need to create an instance of the Equilateral class in order to use this method.
The class Triangle can't see what their children have as methods, so you wouldn't be able to access display_message() with a Triangle object.

Hope that helps, if not, let me know

#3

Thank you, I like to double check that I on the right way.