Triangles

Report a typo

Triangles are geometric figures with 3 sides and equilateral triangles are triangles in which all three sides are equal. Given a triangle, we can calculate its perimeter.

Below you can see classes Triangle and EquilateralTriangle. The class Triangle has a method __init__ with three parameters for three sides and a method get_perimeter that calculates the perimeter of the triangle.

The class EquilateralTriangle should have a method __init__() with 1 parameter since all its sides have equal length. This method is not yet finished.

Your task is to finish the __init__() method for the equilateral triangles in a way that allows us to use the get_perimeter method of the class Triangle without overriding it. Use the function super() for that!

Write a program in Python 3
class Triangle:
def __init__(self, side1, side2, side3):
self.side1 = side1
self.side2 = side2
self.side3 = side3

def get_perimeter(self):
return self.side1 + self.side2 + self.side3


class EquilateralTriangle(Triangle):
def __init__(self, side):
# finish the method
___

Create a free account to access the full topic