Answer to Question #100068 in Python for oladepo

Question #100068
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.
After the Õnal stage of development, print the output of hypotenuse(3, 4) and two other calls to
hypotenuse with diàerent arguments.
Include all of the following:
An explanation of each stage of development, including code and any test input and output.
The output of hypotenuse(3,4).
The output of two additional calls to hypotenuse with diàerent arguments
1
Expert's answer
2019-12-09T14:06:17-0500

Code for solution with comments:

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")

Output of the code:

Test number 1, triangle with legs 3 and 4, hypotenuse is: 5.0

Expected 5

Test number 1, triangle with legs 12 and 5, hypotenuse is: 13.0

Expected 13

Test number 1, triangle with legs 20 and 21, hypotenuse is: 29.0

Expected 29



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS