-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.py
65 lines (56 loc) · 2.13 KB
/
functions.py
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
# functions to run Anzan Apps
from models import AddQuestion, SubtractQuestion
import os
def display_Questions(level, num_questions, qtype):
score = 0
counter = 0
while counter < num_questions:
if qtype == 'add':
question = AddQuestion(level)
sign = '+'
elif qtype == 'subtract':
question = SubtractQuestion(level)
sign = '-'
else:
question = AddQuestion(level)
while True:
print("-------------------------")
print("Level %d : Question # %d" % (level, counter+1))
print("-------------------------")
question_text = " %d %s %d = " % (question.int1, sign, question.int2)
answer = input(question_text)
if answer.isdigit():
answer = int(answer)
break
else:
os.system('clear')
print("Answer Must be an Integer")
if answer == question.ans:
score += 1
counter += 1
os.system('clear')
return score
def display_round_result(level, num_questions, score, total_score, result):
print("===================================")
print(" You ", result, " Level %d" % level)
print(" Score: %d / %d" % (score, num_questions))
print(" Total Score: %d / %d" % (total_score, level * num_questions))
print("===================================")
print("")
def display_all_levels_passed(level, num_questions, total_score):
print(" CONGRATULATIONS!")
print(" YOU PASSED ALL THE LEVELS!")
print("")
print(" Total Score: %d / %d" % (total_score, level * num_questions))
print("")
print("========= END OF GAME =============")
print("")
def display_levels_incomplete(level, num_questions, total_score):
print(" YOUR CHALLENGE IS OVER... :( ")
print("")
print(" Highest Level Passed: %d" % (level-1))
print(" Total Score: %d / %d" % (total_score, level * num_questions))
print(" TRY AGAIN ANOTHER TIME!")
print("")
print("========= END OF GAME ============")
print("")