-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMathQuiz.py
More file actions
40 lines (33 loc) · 894 Bytes
/
MathQuiz.py
File metadata and controls
40 lines (33 loc) · 894 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
# Math Quiz CLI by Sabir Mohammedi Taieb
import random
import time
#time = 0.0
score = 0
correctAns = 0
userSum = 0
#start = 0.0
#finish = 0.0
print("# Math Quiz CLI by Sabir Mohammedi Taieb \n")
print("Write -1 to exit.")
start = time.perf_counter()
while (userSum != -1):
n1 = random.randint(0, 100)
n2 = random.randint(0, 100)
print(n1, " + ", n2)
userSum = input("Enter the sum of these two numbers: ")
userSum = int(userSum)
Sum = n1 + n2
if (userSum == Sum):
print("Correct")
correctAns += 1
elif (userSum == -1):
break
else:
print("Wrong answer! Try again, the correct answer is: ", Sum)
finish = time.perf_counter()
time = finish - start
score = correctAns - time/60
if(correctAns==0):
score=0
print(f"\n Your time was: {time:0.2f} sec. Number of correct answers is:", correctAns, ". Your Score is: ",score)
input("\n Press Enter to exit ...")