Skip to content

Commit

Permalink
Update pythagoras.py
Browse files Browse the repository at this point in the history
Added in error checking for input.
  • Loading branch information
madfolio authored Apr 24, 2017
1 parent 4b41c83 commit 1fee342
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions math/pythagoras.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
"""

def pythagoras(opposite,adjacent,hypotenuse):
if opposite == str("?"):
print ("Solving for opposite")
return ((hypotenuse**2) - (adjacent**2))**0.5
elif adjacent == str("?"):
print ("Solving for adjacent")
return ((hypotenuse**2) - (opposite**2))**0.5
elif hypotenuse == str("?"):
print ("Solving for hypotenuse")
return ((opposite**2)+(adjacent**2))**0.5
else:
return "you already know the answer!"
try:
if opposite == str("?"):
return ("Opposite = " + str(((hypotenuse**2) - (adjacent**2))**0.5))
elif adjacent == str("?"):
return ("Adjacent = " + str(((hypotenuse**2) - (opposite**2))**0.5))
elif hypotenuse == str("?"):
return ("Hypotenuse = " + str(((opposite**2) + (adjacent**2))**0.5))
else:
return "You already know the answer!"
except:
print ("Error, check your input. You must know 2 of the 3 variables.")

0 comments on commit 1fee342

Please sign in to comment.