In models/shape.py
Define a base class Shape with __init__(self, name) method that sets the name attribute.
In models/shape.py
Add two methods to Shape: area(self) and perimeter(self). Both should return 0 as default values (to be overridden by subclasses).
In models/circle.py
Create a Circle class that inherits from Shape. Its __init__(self, radius) should call the parent constructor with name "Circle" and set the radius attribute.
In models/circle.py
Override Circle's area(self) and perimeter(self) methods. Use math.pi for calculations.
- Area: π × radius2
- Perimeter (circumference): 2 × π × radius
In models/rectangle.py
Create a Rectangle class that inherits from Shape. Its __init__(self, width, height) should call the parent constructor with name "Rectangle" and set width and height attributes.
In models/rectangle.py
Override Rectangle's area(self) and perimeter(self) methods.
- Area: width × height
- Perimeter: 2 × (width + height)
In collection.py
Create a ShapeCollection class with:
- __init__(self, shapes) - takes a list of Shape objects
- total_area(self) - returns the sum of all shape areas
- largest_shape(self) - returns the shape with the largest area