Question: For this assignment, write a Rectangle class that must be instantiated with two attributes: length and width. Add an area method to the class that
For this assignment, write a Rectangle class that must be instantiated with two attributes: length and width. Add an area method to the class that returns the area which is length x width.
Next, write a Square class that inherits from the Rectangle class and is instantiated with a single attribute called sideLength.
To test your classes, write a Python program that imports the Rectangle and Square classes then prompts the user to select if they want to calculate the area of a rectangle or square.
If the user selects rectangle, prompt for entry of the length and width then create an instance of the Rectangle class and call the area method to calculate the area of the rectangle.
If the user selects square, prompt for entry of the side length and then create an instance of the Square class and call the area method to calculate the area of the square.
At the end of the program, display type of shape that the user selected and the area that was calclulated.
Put your class definitions in a file called rectangle.py and import this file into your Assignmentpy file with the rest of your code.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
