forked from keon/algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpythagoras.py
More file actions
20 lines (19 loc) · 779 Bytes
/
pythagoras.py
File metadata and controls
20 lines (19 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
"""
Given the lengths of two of the three sides of a right angled triangle, this function returns the
length of the third side.
"""
def pythagoras(opposite, adjacent, hypotenuse):
"""
Returns length of a third side of a right angled triangle.
Passing "?" will indicate the unknown side.
"""
try:
if opposite == str("?"):
return ("Opposite = " + str(((hypotenuse**2) - (adjacent**2))**0.5))
if adjacent == str("?"):
return ("Adjacent = " + str(((hypotenuse**2) - (opposite**2))**0.5))
if hypotenuse == str("?"):
return ("Hypotenuse = " + str(((opposite**2) + (adjacent**2))**0.5))
return "You already know the answer!"
except:
raise ValueError("invalid argument(s) were given.")