easy +10 pts

Abstract Base Class

Implement abstract methods in Rectangle and Circle subclasses.

Define an abstract base class `Shape` using Python's `abc` module. It should have abstract methods `area(self)` and `perimeter(self)`, and a non-abstract method `describe(self)` that returns the string `"Shape with area: {area:.2f}"` where `{area}` is the result of `self.area()`. Then, implement two concrete subclasses: - `Rectangle(length, width)`: `area()` returns `length * width` as a float, `perimeter()` returns `2 * (length + width)` as a float, and it has a method `describe()` that returns `"Rectangle with length {length} and width {width}: area={area:.2f}, perimeter={perimeter:.2f}"`. - `Circle(radius)`: `area()` returns `math.pi * radius * radius` as a float, `perimeter()` returns `2 * math.pi * radius` as a float, and it has a method `describe()` that returns `"Circle with radius {radius}: area={area:.2f}, perimeter={perimeter:.2f}"`. Your task is to implement the missing methods in `Rectangle` and `Circle`. The methods `rectangle_area(length, width)`, `rectangle_perimeter(length, width)`, `circle_area(radius)`, and `circle_perimeter(radius)` are helper functions that create the appropriate object and call the corresponding method. You must implement all the methods in the classes so that these helper functions work correctly.

Constraints

- All inputs are non-negative floats or integers. - The `area()` and `perimeter()` methods should return floats (not integers). - The `describe()` methods should produce exactly the specified string format with two decimal places. - Time complexity O(1) for all methods.

Example

>>> r = Rectangle(4, 5)
>>> r.area()
20.0
>>> r.perimeter()
18.0
>>> r.describe()
'Rectangle with length 4 and width 5: area=20.00, perimeter=18.00'

>>> c = Circle(3)
>>> c.area()
28.274333882308138
>>> c.perimeter()
18.84955592153876
>>> c.describe()
'Circle with radius 3: area=28.27, perimeter=18.85'

>>> rectangle_area(4, 5)
20.0
>>> rectangle_perimeter(4, 5)
18.0
>>> circle_area(3)
28.274333882308138
>>> circle_perimeter(3)
18.84955592153876
10 points ~15 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Use `self.length * self.width` for rectangle area, and `2 * (self.length + self.width)` for perimeter.
Use `math.pi * self.radius * self.radius` for circle area, and `2 * math.pi * self.radius` for perimeter.
Format the describe strings exactly as shown, using f-strings with `:.2f`.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.