Last active
August 29, 2015 13:55
-
-
Save notblizzard/8699090 to your computer and use it in GitHub Desktop.
A way to find the missing side of a triangle.
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
from math import sin, cos, tan | |
#Work on Another Day. | |
def triangle_side_finder(): | |
x = 0 | |
answer = None | |
numbers = True | |
degree = input("What is the degree of the angle?") | |
while numbers == True: | |
try: | |
degree = int(degree) | |
numbers = False | |
except ValueError: | |
print("Not a number!") | |
numbers = True | |
while numbers == True: | |
try: | |
side1 = input("Enter in the measure of side 1 AND the relation(opposite, adjacent, or hypotenuse) with side 1 and the angle") | |
side1 = side1.split(', ') | |
len(side1[0]) > 0 | |
len(side1[1]) > 0 | |
side1[0] = int(side1[0]) | |
side1[1] = str(side1[1]) | |
numbers = False | |
except ValueError: | |
print("You either: made the number negative, you did not enter in a number, or you did not enter in a relation with the side and the angle.") | |
numbers = True | |
while numbers == True: | |
try: | |
side2 = input("Enter in the variable AND the relation(opposite, adjacent, or hypotenuse) with the variable and the angle.") | |
side2 = side2.split(', ') | |
len(side2[0]) > 0 | |
len(side2[1]) > 0 | |
side2[1] = str(side2[1]) | |
numbers = False | |
except ValueError: | |
print("You either: made the number negavite, you did not enter in a number, or you did not enter in a relation with the side and the angle.") | |
x1 = side1[0] | |
x2 = side2[0] | |
x3 = 0 | |
if (side1[1] == 'opposite' and side2[1] == 'hypotenuse'): | |
x3 = sin(degree) | |
answer1 = x3 * side2[0] | |
answerfinal = x1 / answer1 | |
elif (side1[1] == 'hypotenuse' and side2[1] == 'opposite'): | |
x3 = sin(degree) | |
answer1 = x3 * side1[0] | |
answerfinal = x2 / answer1 | |
elif (side1[1] == 'adjacent' and side2[1] == 'hypotenuse'): | |
anglevalue = cos(degree) | |
answer = x1 / anglevalue | |
elif (side1[1] == 'hypotenuse' and side2[1] == 'adjacent'): | |
anglevalue = cos(degree) | |
answer = x1 / anglevalue | |
elif (side1[1] == 'opposite' and side2[1] == 'adjacent'): | |
anglevalue = tan(degree) | |
answer = x1 / anglevalue | |
elif (side1[1] == 'adjacent' and side2[1] == 'opposite'): | |
anglevalue = tan(degree) | |
answer = x1 / anglevalue | |
print("The answer is: {0} = {1}").format(side2[0], answer) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment