A right triangle has sides a and b. Print the length of the longest side, sqrt(a * a + b * b), with two decimal places.
What to build
A program that uses a function from the math module.
Requirements
- Read the two sides.
- Print the longest side with two decimal places.
Input
One line with a and b, two whole numbers from 1 to 10000.
Output
The hypotenuse with two decimal places.
Constraints
Each side is from 1 to 10000.
Example
Input:
3 4
Output:
5.00
Why it works
Pythagoras' rule says that the square of the longest side equals the sum of the other two squares, and math.sqrt undoes the squaring.
Examples
Example 1 · Input
3 4
Expected output
5.00
Example 2 · Input
1 1
Expected output
1.41
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
math.sqrt(x) gives the square root.
Hint 2
math.hypot(a, b) does the whole calculation in one call.
Solution
Show one correct solution (try it yourself first)
import math
a, b = [int(x) for x in input().split()]
print(f"{math.sqrt(a * a + b * b):.2f}")