Rectangle Class
Create a Rectangle class with length and width attributes, and methods area() and perimeter().
What the problem means: model a rectangle as an object that knows its own dimensions and can calculate facts about itself, rather than passing length/width around as loose variables.
Approach: store length and width in init; area() returns length width; perimeter() returns 2 (length + width).
Input: Two lines: the length, then the width.
Output: Two lines: Area: <area> Perimeter: <perimeter>
5 3
Area: 15 Perimeter: 16
- 1 <= length, width <= 10^6
Hint 1
__init__ stores length and width on self so every method can use them.
Hint 2
area() is simply self.length * self.width.
Hint 3
perimeter() is 2 * (self.length + self.width).
The constructor stores length and width as instance attributes (self.length, self.width), so every method on the object can read them. area() multiplies the two dimensions; perimeter() adds them and doubles the result — both are one-line methods once the data lives on self.