Many Shapes, One Loop
Python
20 pts
Many Shapes, One Loop
The Square class is ready. Add two more classes that also have an area() method that returns the area:
Rectangle(width, height)— width × heightCircle(radius)—3.14 * radius * radius
The loop at the bottom prints every shape. Expected output:
Square: 16 Rectangle: 15 Circle: 12.56
Checklist
- Add a class
Rectangle(width, height)with anarea()method that returns width × height. - Add a class
Circle(radius)with anarea()method that returns3.14 * radius * radius. - Keep the
shapeslist and run the loop at the bottom.
🔑 Solution
If you view the solution before passing, you earn half points for this exercise. You still need to type it and press Check to finish.
How it works, step by step
Point at a step to highlight its lines. Type the solution yourself and press Check answer to finish.
