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 three methods:
area
- a method that calculates and returns the area of the rectangle, which is the product of theheight
and thewidth
.
perimeter
- a method that calculates and returns the perimeter of the rectangle. The formula to calculate the perimeter is2 * (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: 1 seconds
Memory limit: 512 MB
Output limit: 1 MB