-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperation Math.py
More file actions
43 lines (28 loc) · 834 Bytes
/
Copy pathoperation Math.py
File metadata and controls
43 lines (28 loc) · 834 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
40
41
42
43
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 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 = end_time -start_time
print("---------------")
print("nice work you finishe" ,total_time ,"seconds" )