Question
Riya, who works as a maths tutor in her free time to teach the orphan kids in her NGO, was now teaching Perimeter calculation to
Riya, who works as a maths tutor in her free time to teach the orphan kids in her NGO, was now teaching Perimeter calculation to the kids. Being a software engineer she always felt lucky as she could easily write code and display it the kids to give a better way of learning. Before going to the class she starts writing code on perimeter calculation. Let's help Riya so that she can reach the NGO earlier.
Write a python program calculate perimeter for different shapes.
Create an abstract classShapewith an abstract methodcalculatePerimeter().
Create a classCirclethat inheritsShapewith following attributes,
AttributesDatatyperadiusFloat
Create a classRectanglethatinheritsShapewith the followingattributes,
AttributesDatatypelengthIntegerbreadthInteger
Create a classSquarethatinheritsShapewith the followingattributes,
AttributesDatatypesideInteger
Implement the methodcalculatePerimeter()in all the child classes to calculate appropriate perimeters.
Note: Use math.pi for pi value and display 2 digits after decimal in the answer.
Refer to sample input/output for other further details and format of the output.
[All Texts in bold corresponds to the input and rest are output]
Sample Input/Output 1:
List of Shapes:
1.Circle
2.Rectangle
3.Square
Enter your choice:
1
Enter the radius of the Circle:
2.34
The perimeter is 14.70
Sample Input/Output 2:
List of Shapes:
1.Circle
2.Rectangle
3.Square
Enter your choice:
2
Enter the length of the Rectangle:
12
Enter the breadth of the Rectangle:
3
The perimeter is 30.00
Sample Input/Output 3:
List of Shapes:
1.Circle
2.Rectangle
3.Square
Enter your choice:
3
Enter the side of the Square:
13
The perimeter is 52.00Riya, who works as a maths tutor in her free time to teach the orphan kids in her NGO, was now teaching Perimeter calculation to the kids. Being a software engineer she always felt lucky as she could easily write code and display it the kids to give a better way of learning. Before going to the class she starts writing code on perimeter calculation. Let's help Riya so that she can reach the NGO earlier.
Write a python program calculate perimeter for different shapes.
Create an abstract classShapewith an abstract methodcalculatePerimeter().
Create a classCirclethat inheritsShapewith following attributes,
AttributesDatatyperadiusFloat
Create a classRectanglethatinheritsShapewith the followingattributes,
AttributesDatatypelengthIntegerbreadthInteger
Create a classSquarethatinheritsShapewith the followingattributes,
AttributesDatatypesideInteger
Implement the methodcalculatePerimeter()in all the child classes to calculate appropriate perimeters.
Note: Use math.pi for pi value and display 2 digits after decimal in the answer.
Refer to sample input/output for other further details and format of the output.
[All Texts in bold corresponds to the input and rest are output]
Sample Input/Output 1:
List of Shapes:
1.Circle
2.Rectangle
3.Square
Enter your choice:
1
Enter the radius of the Circle:
2.34
The perimeter is 14.70
Sample Input/Output 2:
List of Shapes:
1.Circle
2.Rectangle
3.Square
Enter your choice:
2
Enter the length of the Rectangle:
12
Enter the breadth of the Rectangle:
3
The perimeter is 30.00
Sample Input/Output 3:
List of Shapes:
1.Circle
2.Rectangle
3.Square
Enter your choice:
3
Enter the side of the Square:
13
The perimeter is 52.00
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started