-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstn53_khy9_lab3_mathQuiz.py
182 lines (170 loc) · 6.34 KB
/
stn53_khy9_lab3_mathQuiz.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
from random import randint
print('What difficulty would you like?')
difficulty = input('BEGINNER, INTERMEDIATE, ADVANCED\n')
question_total = int(input('How many questions would you like?'))
correct = 0
questions_asked = 0
if difficulty == 'BEGINNER':
while questions_asked < question_total:
operator = randint(1, 2)
if operator == 1:
n1 = randint(1, 10)
n2 = randint(1, 10)
sum = n1 + n2
ans = input(f"What's {n1} plus {n2}? ")
if int(ans) == sum:
print("That's right -- well done.\n")
correct += 1
questions_asked += 1
else:
print(f"No, I'm afraid the answer is {sum}.\n")
questions_asked += 1
else:
n1 = randint(1, 10)
n2 = randint(1, 10)
diff = n1 - n2
ans = input(f"What's {n1} minus {n2}?\n")
if int(ans) == diff:
print("That's right -- well done. \n")
correct += 1
questions_asked += 1
else:
print(f"No, I'm afraid the answer is {diff}.\n")
questions_asked += 1
elif difficulty == 'INTERMEDIATE':
while questions_asked < question_total:
operator = randint(1, 4)
if operator == 1:
n1 = randint(1, 25)
n2 = randint(1, 25)
sum = n1 + n2
ans = input(f"What's {n1} plus {n2}?\n")
if int(ans) == sum:
print("That's right -- well done.\n")
correct += 1
questions_asked += 1
else:
print(f"No, I'm afraid the answer is {sum}.\n")
questions_asked += 1
elif operator == 2:
n1 = randint(1, 25)
n2 = randint(1, 25)
diff = n1 - n2
ans = input(f"What's {n1} minus {n2}?\n")
if int(ans) == diff:
print("That's right -- well done. \n")
correct += 1
questions_asked += 1
else:
print(f"No, I'm afraid the answer is {diff}.\n")
questions_asked += 1
elif operator == 3:
n1 = randint(1, 25)
n2 = randint(1, 25)
prod = n1 * n2
ans = input(f"What's {n1} times {n2}?\n")
if ans == '':
print(f"No, I'm afraid the answer is {prod}.\n")
questions_asked += 1
if int(ans) == prod:
print("That's right -- well done. \n")
correct += 1
questions_asked += 1
else:
print(f"No, I'm afraid the answer is {prod}.\n")
questions_asked += 1
else:
n1 = randint(1, 25)
n2 = randint(1, 25)
quot = round((n1 / n2), 2)
ans = float(input(f"What's {n1} divided {n2}?\n"))
round_ans = round(ans, 2)
if (round_ans) == quot:
print("That's right -- well done. \n")
correct += 1
questions_asked += 1
else:
print(f"No, I'm afraid the answer is {quot}.\n")
questions_asked += 1
elif difficulty == 'ADVANCED':
while questions_asked < question_total:
operator = randint(1, 5)
if operator == 1:
n1 = randint(1, 25)
n2 = randint(1, 25)
n3 = randint(1, 25)
sum_diff = n1 + n2 - n3
ans = input(f"What's {n1} plus {n2} - {n3}?\n")
if int(ans) == sum_diff:
print("That's right -- well done.\n")
correct += 1
questions_asked += 1
else:
print(f"No, I'm afraid the answer is {sum_diff}.\n")
questions_asked += 1
elif operator == 2:
n1 = randint(1, 25)
n2 = randint(1, 25)
n3 = randint(1, 25)
prod_diff = n1 * n2 - n3
ans = input(f"What's {n1} times {n2} minus {n3}?\n")
if ans == '':
print(f"No, I'm afraid the answer is {prod_diff}.\n")
questions_asked += 1
elif int(ans) == prod_diff:
print("That's right -- well done. \n")
correct += 1
questions_asked += 1
else:
print(f"No, I'm afraid the answer is {prod_diff}.\n")
questions_asked += 1
elif operator == 3:
n1 = randint(1, 25)
n2 = randint(1, 25)
n3 = randint(1, 25)
sum_prod = n1 + n2 * n3
ans = input(f"What's {n1} plus {n2} times {n3}?\n")
if int(ans) == sum_prod:
print("That's right -- well done. \n")
correct += 1
questions_asked += 1
else:
print(f"No, I'm afraid the answer is {sum_prod}.\n")
questions_asked += 1
elif operator == 4:
n1 = randint(1, 25)
n2 = randint(1, 25)
n3 = randint(1, 25)
prod_prod = n1 * n2 * n3
ans = input(f"What's {n1} times {n2} times {n3}?\n")
if ans == prod_prod:
print("That's right -- well done. \n")
correct += 1
questions_asked += 1
else:
print(f"No, I'm afraid the answer is {prod_prod}.\n")
questions_asked += 1
else:
n1 = randint(1, 25)
n2 = randint(1, 25)
n3 = randint(1, 25)
quot = round((n1 / n2), 2)
sum_quot = n3 + quot
ans = float(input(f"What's {n1} divided {n2} plus {n3}?\n"))
round_ans = round(ans, 2)
if (round_ans) == sum_quot:
print("That's right -- well done. \n")
correct += 1
questions_asked += 1
else:
print(f"No, I'm afraid the answer is {sum_quot}.\n")
questions_asked += 1
print(f"\nI asked you {question_total} questions. You got {correct} of them right.")
upper = question_total * (2/3)
lower = question_total * (1/3)
if correct <= question_total and correct >= upper:
print(f"\nWell Done!")
elif correct < upper and correct >= lower:
print(f"\nYou need more practice")
else:
print(f"\nPlease ask your math teacher for help")