The hypotenuse
- O(1) · Trivial
- Free
- Python
- JavaScript
- operations
- decimals
Problem
In a right triangle, the hypotenuse is the long side: it measures the square root of the sum of the other two sides squared.
Write a function that takes those two sides and returns the hypotenuse. With 3 and 4 you return 5. With 1 and 1 you return 1.4142..., so the answer can come with decimals and you don't round it. The sides are positive.
To get a square root, raising to 0.5 does the job.
Examples
The classic triangle
3, 4 → 5
6, 8 → 10
Both sides equal
1, 1 → 1.4142
Besides these, the challenge has hidden tests that are revealed when you submit your solution.
You start with this
Python
def hypotenuse(a, b):
passJavaScript
function hypotenuse(a, b) {
}Solve this challenge
It opens in your browser, with the editor and the tests. It is free and you do not need an account to start.