Build a small class hierarchy, then answer one question about it per call.
solve(aspect) returns { aspect: value } — a single-key dict naming what was
asked. The grader compares JSON, so it asks for one aspect at a time rather than
for the classes themselves.
The hierarchy
Shape (base class)
__init__(self, color: str)describe(self) -> str returns "I am a {color} shape."Circle (extends Shape)
__init__(self, color: str, radius: float)area(self) -> float returns π × radius² (use math.pi)describe(self) → "I am a {color} circle with radius {radius}."Rectangle (extends Shape)
__init__(self, color: str, width: float, height: float)area(self) -> float returns width × heightdescribe(self) → "I am a {color} rectangle of {width}x{height}."The aspects
| aspect | value to return |
|---|---|
shape_describe | Shape("blue").describe() |
circle_describe | Circle("red", 5).describe() |
circle_area_approx | Circle("red", 5).area() rounded to 2 decimals |
circle_area_unit | Circle("red", 1).area() |
rectangle_describe | Rectangle("green", 4, 6).describe() |
rectangle_area | Rectangle("green", 4, 6).area() |
circle_is_shape | whether a Circle is an instance of Shape |
rectangle_is_shape | whether a Rectangle is an instance of Shape |
Example
solve("circle_describe") # {"circle_describe": "I am a red circle with radius 5."}
solve("rectangle_area") # {"rectangle_area": 24}In JavaScript / TypeScript — Use class … extends Shape and super(color); the area is Math.PI * radius ** 2, rounded to two decimals for circle_area_approx, and instanceof answers the *_is_shape aspects.
Sample tests