一個(gè)例子是在計(jì)算直角三角形的斜邊長度時(shí),可以使用hypot函數(shù)來計(jì)算。假設(shè)有一個(gè)直角三角形,其中一條直角邊的長度為3,另一條直角邊的長度為4??梢允褂胔ypot函數(shù)來計(jì)算斜邊的長度:
import math
side1 = 3
side2 = 4
hypotenuse = math.hypot(side1, side2)
print("The length of the hypotenuse is:", hypotenuse)
在這個(gè)例子中,hypot函數(shù)會(huì)返回斜邊的長度為5。