hypot() function is an inbuilt math function in Python that return the Euclidean norm, .
x and y are numerical values
Returns a float value having Euclidean norm, sqrt(x*x + y*y).
When more then two arguments are passed, it returns a TypeError.
Note : One has to import math module before using hypot() function.
Below is the demonstration of hypot() function :
Code #1 :
hypot(3, 4) : 5.0 hypot(-3, 4) : 5.0 hypot(6, 6) : 8.48528137423857
Code #2 :
Traceback (most recent call last): File "/home/d8c8612ee97dd2c763e2836de644fac1.py", line 7, in print("hypot(3, 4, 6) : ", math.hypot(3, 4, 6)) TypeError: hypot expected 2 arguments, got 3
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.
Hypotenuse = sqrt(p^2 + b^2)
Code #3 :
Hypotenuse is: 5.0
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course