Rectangle Measurements
Python
25 pts
Rectangle Measurements
Create a class called Rectangle. Its __init__ takes width and height and stores four attributes:
self.widthandself.heightself.area— width × heightself.perimeter— 2 × (width + height)
Create r = Rectangle(5, 3) and print its area and perimeter:
Area: 15 Perimeter: 16
Checklist
- Define a class called
Rectanglewhose__init__storeswidthandheight. - In
__init__, also calculate and storeareaandperimeter. - Create
r = Rectangle(5, 3)and print its area and perimeter.
🔑 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.
