1. A polygon is a plane figure enclosed by line segments called sides.
The following are examples of polygons and random colors. Assume all sides length are equal for
each shape.
A polygon can have three
or more sides.
Regular Polygons
all sides are equal length and
all internal angles are equal.
3 sides
Triangle
4 sides
Quadrilateral
5 sides
Pentagon
6 sides
Hexagon
Your task is to create classes to represent the area calculation result for each shape and its color.
Use the following python code and add all suitable attributes and methods to complete the code to
test 4 cases for the 4 shapes. (Note: Side is the length of the side)
class Poloygon:
def __init__(self, name, side, color):
self.name = name
self.side = side
self.color = color
def area(self):
pass
def __str__(self):
return 'This poloygon is a '+self.name+' that has a color '+self.color+' and area='+str(self.area())
class Triangle(Poloygon):
def __init__(self, side):
Write your own code
def area(self):
Find the formula and Write your own code
class Quad(Poloygon):
def __init__(self, side):
Write your own code
def area(self):
Find the formula and Write your own code
class Pentagon(Poloygon):
def __init__(self, side):
Write your own code
def area(self):
Find the formula and Write your own code
class Hexagon(Poloygon):
def __init__(self, side):
Write your own code
def area(self):
Find the formula and Write your own code
a = Triangle(4)
b = Quad(3)
c = Pentagon(6)
d = Hexagon(4)
print(a)
print(b)
print(c)
print(d)