-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject 5.py
More file actions
36 lines (28 loc) · 909 Bytes
/
Copy pathproject 5.py
File metadata and controls
36 lines (28 loc) · 909 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
#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
end_time =time.time()
total_time = end_time - start_time
print("--------------------")
print(f"Nice work! you finished in {total_time},seconds")