![]() |
VOOZH | about |
math.hypot() function in Python is used to compute the Euclidean distance from the origin (0, 0) to a point (x, y) in a 2D plane. It calculates the hypotenuse of a right triangle, given the lengths of the two other sides.
5.0
Explanation:
In this example, the two sides of the right triangle are 3 and 4. The hypot() function calculates the hypotenuse as:
Thus, the output is 5.0, which is the length of the hypotenuse.
math.hypot(x, y)
Parameters
Return Type
Error
Note : One has to import math module before using hypot() function.
This example demonstrates how the hypot() function works with positive and negative values to compute the hypotenuse.
hypot(3, 4) : 5.0 hypot(-3, 4) : 5.0 hypot(6, 6) : 8.48528137423857
Explanation
This example shows an error when an incorrect number of arguments is passed to the hypot() function (more than two arguments).
hypot(3, 4, 6) : 7.810249675906654
Explanation
Practical Application : Given perpendicular and base of a right angle triangle find the hypotenuse. Using Pythagorean theorem which states that the square of the hypotenuse (the side opposite the right angle) is equal to the sum of the squares of the other two sides.
This example demonstrates how to use the hypot() function to calculate the hypotenuse of a right triangle given the perpendicular and base.
Hypotenuse is: 5.0
Explanation