-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject3_TimeMathChallenge.py
More file actions
45 lines (31 loc) · 1.27 KB
/
Project3_TimeMathChallenge.py
File metadata and controls
45 lines (31 loc) · 1.27 KB
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
# maths problem challenge
# also calculate time in how much time you solved the ques
import random
import time
operators = ["+", "-", "*"]
min_operand = 3
max_operand = 12
total_ques = 10
def create_challenge():
# generating rand values for oper, and both the operands
left = random.randint(min_operand, max_operand) # for left num e.g 2+4 (2 here is on left) and similarly for right as well
right = random.randint(min_operand, max_operand)
operator = random.choice(operators) # choice picks up random operators from the above list
expr=str(left) + operator + str(right) # left and right both should gonna be a string
answer=eval(expr)
return expr,answer # return both the expression and its ans
wrong = 0
input("Press any key to start!")
start_time = time.time()
for i in range(total_ques):
expr, answer = create_challenge()
while True:
guess = input("Problem " + str(i + 1) + ": " + expr + " = ") #conv i+1 into a string
if guess == str(answer):
break
else:
print("Your answer is incorrect! Please Try Again")
wrong += 1
end_time = time.time()
total_time = round(end_time - start_time, 2)
print("Nice work! You finished in", total_time, "seconds!")