use incremental development to write a function called hypotenuse that returns the length of the hypotenuse of a right triangle given the lengths of the other two legs as arguments. Record each stage of the development process as you go. (PYTHON)
Answers
Answered by
0
Answer:
def hypotenuse(leg1,leg2): #our function has 2 arguments for first leg and second leg respectively
return (leg1**2+leg2**2)**(1/2) #according to Pythagorean theorem, the hypotenuse is equal to the square root of the sum of the squares of the legs
print("Test number 1, triangle with legs 3 and 4, hypotenuse is:",hypotenuse(3,4))#prints the call for triangle with legs 3 and for
print("Expected 5")#expected result
print("Test number 1, triangle with legs 12 and 5, hypotenuse is:",hypotenuse(12,5))#same for 12 and 5
print("Expected 13")
print("Test number 1, triangle with legs 20 and 21, hypotenuse is:",hypotenuse(20,21))#20 and 29
print("Expected 29")
Similar questions