Question: Define three classes, Polygon, Rectangle and Square. Polygon will be the parent class of Triangle and Square. The Polygon should have a function called WhoAmI
Define three classes, Polygon, Rectangle and Square. Polygon will be the parent class of Triangle and Square.
The Polygon should have a function called WhoAmI and it should print out Triangle if the current object is a triangle or Square if the current object is a square.
When you create a Rectangle object it should generate 2 random integers as the sides of the rectangle and store the values in the class.
Similarly, for Square it should randomly generate 1 random integer to denote one side of the square and store it in the class.
Also, each of the Rectangle and Square classes should have a function called findArea that computes and returns the Polygon area.
The Polygon should have a function called side_lengths to print the side lengths of the polygon.
The sides can be any value between 1 and 100, Inclusively.
Create 5 Triangle and 5 Square objects and print out all the properties in a loop.
It would be best if you mimicked this behaviour.
rect_obj = Rectangle()
sq_obj = Square()
rect_obj.WhoAmI()
Output "Rectangle"
rect_obj.side_lengths()
Output: [5,6] // Random integers that were chosen
rect_obj.findArea()
Output: 30
sq_obj.WhoAmI()
Output: "Square"
sq_obj.side_lengths()
Output: [6]
sq_obj.findArea()
Output: 36
for more clarification please find below picture and coding and explain it
**Clarification**
Assignmnet2.Q3.
Instead of:
Define three classes, Polygon, Rectangle and Square. Polygon will be the parent class of Triangle and Square.
Please consider:
Define four classes, Polygon, Rectangle, Square, and Triangle. Polygon is the parent class of Rectangle, which is the parent class of Square. Polygon also is the parent class of the Triangle class.
This figure might be helpful to visualize the control flow of the required program.

class Polygon def init_(self, no_of_unique_sides) def who am_i ( self ) def area (self) def side_lengths (self) class class Rectangle (Polygon ) Triangle (Polygon) def def init_(self) init (self) def def area (self) area (self ) class Square ( Rectangle) def init_(self) def area (self)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
