"""=========================== exercise 6.2 ==============================""" import math #stage 1 """def hypotenuse (leg_a, leg_b): return 0.0""" #stage 2 """def hypotenuse (leg_a, leg_b): a_squared = leg_a**2 b_squared = leg_b**2 print "a_squared = ", a_squared print "b_squared = ", b_squared return 0.0""" def hypotenuse (leg_a, leg_b): a_squared = leg_a**2 b_squared = leg_b**2 leg_c = math.sqrt(a_squared + b_squared) return leg_c print (hypotenuse(3,4)) # should equal 5.0 print (hypotenuse(2,2)) # should equal 2*sqrt(2)
Solutions and answers to help you learn Python using the Think Python programming textbook
Sunday, March 18, 2012
exercise 6.2 - hypotenuse
Labels:
exercise,
thinkpython
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.