August 2024
Intermediate to advanced
256 pages
5h 34m
English
Create a parent class called “Shape” that represents a geometric shape. The Shape class should have the following attributes:
The Shape class should also have a method called “display_info()” that prints the shape’s name and color.
Next, create two child classes called “Rectangle” and “Circle” that inherit from the Shape class.
The Rectangle class should have additional attributes:
The Circle class should have an additional attribute:
Add a method called “calculate_area()” to the Rectangle and Circle classes to calculate the area. Remember the area of a circle is πr2 and the area of a rectangle is length x width.
Write a program to implement the class.
Read now
Unlock full access