Rectangle Class

You are asked to design a Rectangle class in Python. This class should have two attributes:
  • height - which represents the height of the rectangle
  • width - which represents the width of the rectangle
The class should also include two methods:
  • area - a method that calculates and returns the area of the rectangle, which is the product of the height and the width.
  • perimeter - a method that calculates and returns the perimeter of the rectangle. The formula to calculate the perimeter is 2 * (height + width).
  • diagonal - a method that computes and returns the length of the diagonal of the rectangle.
    • 💭
      Remember the Pythagorean theorem
 
Input
Output
r = Rectangle(10, 5); print(r.area())
50
 

Constraints

Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue