The hypotenuse is the longest side of a right triangle. It is also the side that is not opposite the right angle.
If you’re trying to find the hypotenuse of a right-angled triangle, you can use the following equation:
h = (a^2 + b^2)
Where h is the hypotenuse, a and b are the lengths of the other two sides, and x is the angle at which the triangle is drawn.
Table of Contents
show
Program Code
from math import sqrt
a = float(input('Enter the length of the shorter triangle side: '))
b = float(input('Enter the length of the other shorter triangle side: '))
c = sqrt(a**2 + b**2)
print('The length of the hypotenuse is', c)
Input Given:
Enter the length of the shorter triangle side: 3 Enter the length of the other shorter triangle side: 4
Expected Output:
The length of the hypotenuse is 5.0
Code Explanation
- We import the sqrt function from the math module.
- We ask the user to enter the length of the shorter triangle side.
- We ask the user to enter the length of the other shorter triangle side.
- We calculate the length of the hypotenuse using the Pythagorean theorem.
- We print the length of the hypotenuse.