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 rectanglewidth
- 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.
Input | Output |
---|---|
| 50 |
Constraints
Time limit: 2 seconds
Memory limit: 512 MB
Output limit: 1 MB