Last active
July 16, 2021 13:34
-
-
Save minte9/9e15623532be8bc01dfca94efa82625d to your computer and use it in GitHub Desktop.
Python / Language / Incremental development - https://www.minte9.com/python/math-development-1257
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use incremental development to write a function called hypotenuse | |
# The function returns the length of the hypotenuse of a right triangle | |
# The function gets the other two legs as arguments | |
# Record each stage of the development | |
# SOLUTION | |
# v1.0 -------------------------- | |
def hypotenuse(a, b): | |
return 0 | |
print (hypotenuse(3,4)) # 0 | |
# v2.0 ------------------------- | |
def hypotenuse(a, b): | |
sum = a**2 + b**2 | |
return sum | |
print(hypotenuse(3, 4)) # 25 | |
# v3.0 ------------------------- | |
import math | |
def hypotenuse(a, b): | |
sum = a**2 + b**2 | |
return math.sqrt(sum) | |
print(hypotenuse(3, 4)) # 5.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment