forked from Zandew/Quiz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
round3.py
108 lines (106 loc) · 3.49 KB
/
round3.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import random, math
'''
|\
|◡\
|b \
| \ C
A | \
| \
| \
|_ a\
|_|_____(\
B
'''
def r3():
var = ['A', 'B', 'C', 'a', 'b']
val1 = random.randint(10, 100)
var1 = var[random.randint(0,2)]
solveForSide = random.randint(0, 1)==0
val2 = None
var2 = None
unknown = None
if (solveForSide):
var2 = var[random.randint(3, 4)]
val2 = random.randint(1, 89)
unknown = var[random.randint(0, 2)]
while (unknown == var1):
unknown = var[random.randint(0, 2)]
else:
var2 = var[random.randint(0, 2)]
while (var2 == var1):
var2 = var[random.randint(0, 2)]
if (var2 == 'C'):
val2 = random.randint(val1+1, 100)
elif (var1 == 'C'):
val2 = random.randint(10, val1-1)
else:
val2 = random.randint(10, 100)
unknown = var[random.randint(3, 4)]
print("Given: \n"+str(var1)+" = "+str(val1)+" units\n"+str(var2)+" = "+str(val2)+(" degrees" if solveForSide else " units"))
print("Solve for "+str(unknown))
userAns = int(input("Enter your answer rounded to the nearest integer: "))
ans = None
if (solveForSide):
val2 = math.radians(val2)
if (var1 == 'A'):
if (var2 == 'a'):
if (unknown == 'B'):
ans = round(val1/math.tan(val2))
else:
ans = round(val1/math.sin(val2))
else:
if (unknown == 'B'):
ans = round(val1*math.tan(val2))
else:
ans = round(val1/math.cos(val2))
elif (var1 == 'B'):
if (var2 == 'a'):
if (unknown == 'A'):
ans = round(val1*math.tan(val2))
else:
ans = round(val1/math.cos(val2))
else:
if (var2 == 'b'):
if (unknown == 'A'):
ans = round(val1/math.tan(val2))
else:
ans = round(val1/math.sin(val2))
else:
if (var2 == 'a'):
if (unknown == 'A'):
ans = round(val1*math.sin(val2))
else:
ans = round(val1*math.cos(val2))
else:
if (unknown == 'A'):
ans = round(val1*math.cos(val2))
else:
ans = round(val1*math.sin(val2))
else:
if (var1 in 'AB' and var2 in 'AB'):
A = val1 if (var1 == 'A') else val2
B = val2 if (var1 == 'A') else val1
if (unknown == 'a'):
ans = round(math.degrees(math.atan(A/B)))
else:
ans = round(math.degrees(math.atan(B/A)))
elif (var1 in 'BC' and var2 in 'BC'):
B = val1 if (var1 == 'B') else val2
C = val2 if (var1 == 'B') else val1
if (unknown == 'a'):
ans = round(math.degrees(math.acos(B/C)))
else:
ans = round(math.degrees(math.asin(B/C)))
else:
A = val1 if (var1 == 'A') else val2
C = val2 if (var1 == 'A') else val1
if (unknown == 'a'):
ans = round(math.degrees(math.asin(A/C)))
else:
ans = round(math.degrees(math.acos(A/C)))
if (userAns == ans):
print("You are correct!")
else:
print("You are wrong! The correct answer is "+str(ans))
return userAns == ans
print(r3())