-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathmain.py
More file actions
86 lines (77 loc) · 2.72 KB
/
main.py
File metadata and controls
86 lines (77 loc) · 2.72 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
################################################
# Simple test simulator.
# See README and LICENSE
################################################
from questengine import QuestionEngine
from helpers import bc, ask, clear
# Main
if __name__ == "__main__":
qe = QuestionEngine()
qc = 0
clear()
while True:
qc = input("How many questions do you want to practice? 1-{} (X to exit): \n"
.format(qe.totalQuestions))
if qc == "x" or qc == "X":
exit()
elif qc.isdigit() and (int(qc) > 0
and int(qc) <= qe.totalQuestions):
break
else:
clear()
i = 0
is_done = False
result = None
while True:
try:
qn = i + 1
clear()
print("Question {} of {} (X to exit)\n".format(qn, qc))
result = ask(i, qe)
if result == 'correct':
print("\n{}Correct!!! The Answer is: {}\n\n{}".format(bc.OKGREEN, qe.getSolutionText(i), bc.ENDC))
qe.correct += 1
i += 1
elif result == 'wrong':
print("\n{} Wrong!!! The correct Answer is: {}{}\n\n{}".format(bc.WARNING,
bc.OKGREEN, qe.getSolutionText(i), bc.ENDC))
qe.incorrect += 1
i += 1
elif result == "exit":
qn = qc
if int(qn) == int(qc):
raise Exception()
else:
input("Press ENTER to continue...")
except Exception as e:
if int(qn) == int(qc):
input("Press ENTER to view results...")
break
else:
pass
clear()
answered = qe.correct + qe.incorrect
right = qe.correct
wrong = qe.incorrect
if answered == 0:
righta = "0.0"
wronga = "0.0"
else:
righta = int(right) / int(answered) * 100
wronga = wrong / int(answered) * 100
rightq = int(right) / int(qc) * 100
wrongq = wrong / int(qc) * 100
skipq = int(qc) - int(answered)
print("Results:")
print("Questions answered: {} of {}\n".format(answered, qc))
print("Scores from questions answered:")
print("{}# Right: {} {}% {}".format(
bc.OKGREEN, str(right), righta, bc.ENDC))
print("{}# Wrong: {} {}% \n{}".format(
bc.WARNING, str(wrong), wronga, bc.ENDC))
print("Scores from total questions")
print("{}# Right: {} {}% {}".format(
bc.OKGREEN, str(right), rightq, bc.ENDC))
print("{}# Wrong: {} {}% {}".format(
bc.WARNING, str(wrong), wrongq, bc.ENDC))
print("{}# Skipped: {}\n{}".format(bc.WARNING, skipq, bc.ENDC))