Skip to content
C

Rectangle Class

Easypython

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>

Input (stdin)

Output

Run your code to see output here...