This is in Python Write a Rectangle class that must be instantiated with two attributes: .length and .width. Add an .ar

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

This is in Python Write a Rectangle class that must be instantiated with two attributes: .length and .width. Add an .ar

Post by answerhappygod »

This is in Python
Write a Rectangle class that must be instantiated with twoattributes: .length and .width. Add an .area() method to theclass that returns the area (length * width) of the rectangle.
Then write a Square class that inherits from the Rectangle classand is instantiated with a single attribute called .side_length.Test your Square class by instantiating a Square with a.side_length of 4. Calling .area() should return 16.
Set the .width property of your Square instance to 5. Then call.area() again. The return value should be 20.
Be careful to define behaviors so that they reflectexpectations, and use class hierarchies with caution.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply