Rectangle That Measures Itself

Python for AIEasy+10 XP+10

Rectangle That Measures Itself

Give Rectangle three methods. Each one returns its answer.

  • area(): width times height.
  • perimeter(): the distance all the way round, 2 * (width + height).
  • is_square(): True when width and height are equal.

Examples

Rectangle(2, 6).area()
returns 12
Rectangle(2, 6).is_square()
returns False
Rectangle(3, 4).area()
returns 12
Rectangle(3, 4).perimeter()
returns 14

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run