-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimed Math Challenge.py
More file actions
39 lines (30 loc) · 961 Bytes
/
Timed Math Challenge.py
File metadata and controls
39 lines (30 loc) · 961 Bytes
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
#timed math challenge
import random
import time
OPERATORS = ["+", "-", "*"]
MIN_OPERAND = 3
MAX_OPERAND = 12
TOTAL_PROBLEMS = 10
def generate_problem():
left = random.randint(MIN_OPERAND, MAX_OPERAND)
right = random.randint(MIN_OPERAND, MAX_OPERAND)
operator = random.choice(OPERATORS)
expr = str(left) + " " + operator + " " + str(right)
answer = eval(expr)
return expr, answer
wrong = 0
input("Press enter to start!")
print("---------------------------")
start_time = time.time()
for i in range(TOTAL_PROBLEMS):
expr, answer = generate_problem()
while True:
guess= input("Problem #" + str(i+1) + ": " + expr + " = " )
if guess == str(answer):
break
wrong += 1
end_time = time.time()
total_time = round(end_time - start_time)
print("---------------------------")
print("Good work! You finished in", total_time, "seconds!")
#End of program