-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathtrigonometric functions.py
78 lines (68 loc) · 2.92 KB
/
trigonometric functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import math
import numpy
from fractions import Fraction
sin_answers = ['sin', 'sine', 's', 'Sine', 'Sin']
cos_answers = ['cos', 'cosine', 'c', 'Cosine']
tan_answers = ['tan', 'tangent', 't', 'Tangent']
# Get input from user
loop = True
while loop:
user = input('What trigonometric function do you need help with (Sin, Cosine, Tangent)? ')
if user in sin_answers:
break
elif user in cos_answers:
break
elif user in tan_answers: #Loop will only break if the user's answers was part of the answers in the lists above
break
else:
print('')
print('That was not a valid answer. Please try again.')
print('')
if user in sin_answers: #These functions are specific to sin only
loop2 = True
while loop2:
try:
print('')
user2 = input('Please enter the amount of radians, or type "break" if you want to stop the loop: ')
sin = math.sin(float(user2))
print('The sin of ' + str(user2) + ' radians is:' + str(sin) + '\n\nRounded it is: ' + str(round(sin, 4)) + ' radians.\n\nIn degrees, it is: ' + str(math.degrees(sin)) + ' degrees.')
except ValueError as e: #This error is to handle the user entering anything other than numbers
print('')
print('Loop broken! The program will now automatically stop running. Have a nice day!')
break
except TypeError as e: #This error is to handle the program mishandling numbers
print('')
print('There was an error concacenating the numbers. Please reload the program.')
break
elif user in cos_answers: #This function is specific to cos only
loop3 = True
while loop3:
try:
print('')
user2 = input('Please enter the amount of radians, or type "break" if you want to stop the loop: ')
cos = math.cos(float(user2))
print('The cosine of ' + str(user2) + ' radians is: ' + str(cos) + '\n\nRounded it is: ' + str(round(cos, 4)) + ' radians.\n\nIn degrees, it is: ' + str(math.degrees(cos)) + ' degrees.')
except ValueError as e:
print('')
print('Loop broken! The program will now automatically stop running. Have a nice day!')
break
except TypeError as e:
print('')
print('There was an error concacenating the numbers. Please reload the program.')
break
elif user in tan_answers: #This function is specific to tan only
loop4 = True
while loop4:
try:
print('')
user2 = input('Please enter the amount of radians, or type "break" if you want to stop the loop: ')
tan = math.tan(float(user2))
print('The tangent of ' + str(user2) + ' radians is: ' + str(tan) + '\n\nRounded it is: ' + str(round(tan, 4)) + ' radians.\n\nIn degrees, it is: ' + str(math.degrees(tan)) + ' degrees.')
except ValueError as e:
print('')
print('Loop broken! The program will now automatically stop running. Have a nice day!')
break
except TypeError as e:
print('')
print('There was an error concacenating the numbers. Please reload the program.')
break