Classes of 2D Geometric Shapes

In the realm of 2-dimensional geometrical shapes, polygons form the basics. In this challenge, your task is to create classes representing four types of polygons: Polygon, Triangle, Rectangle, and Pentagon.
A polygon is defined by its number of sides. Therefore, the Polygon class should contain an attribute sides representing the number of sides of the polygon.
The Polygon class also needs a method describe() which prints "A polygon" when called.
Next, create Triangle, Rectangle, and Pentagon classes that inherit from the Polygon class. Each of these classes should override the describe() method to print "A triangle", "A rectangle", and "A pentagon" respectively, when called. This way, each specific type of polygon will be able to announce what it is when the describe() method is called.
polygon, triangle, rectangle, pentagon = Polygon(10), Triangle(), Rectangle(), Pentagon(); polygon.describe(); print('Polygon sides:', polygon.sides); triangle.describe(); print('Triangle sides:', triangle.sides); rectangle.describe(); print('Rectangle sides:', rectangle.sides); pentagon.describe()
A polygon Polygon sides: 10 A triangle Triangle sides: 3 A rectangle Rectangle sides: 4 A pentagon


Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue