-
Notifications
You must be signed in to change notification settings - Fork 1
/
professor.py
81 lines (59 loc) · 1.71 KB
/
professor.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from random import randint
def main():
level = get_level()
# INIT
question = 0
correct = 0
while question < 10:
# COUNT ERRORS
eee = 0
# GENERATE X AND Y
x = generate_integer(level)
y = generate_integer(level)
while True:
try:
# USER INPUT TO X + Y
answer = int(input(f"{x} + {y} = "))
# CHECK IF INPUT INCORRECT
if answer != x + y:
print("EEE")
eee += 1
# 3 STRIKES REVEAL ANSWER AND MOVE TO NEXT
if eee == 3:
print(f"{x} + {y} = {x+y}")
question += 1
break
else:
question += 1
correct += 1
break
# INVALID INPUT IS INCORRECT ANSWER
except ValueError:
print("EEE")
eee += 1
if eee == 3:
print(f"{x} + {y} = {x+y}")
question += 1
break
print("Score:", correct)
def get_level():
# INIT VALID LEVELS
levels = [1, 2, 3]
while True:
try:
level = int(input("Level: "))
if level in levels:
return level
# CATCH INVALID INPUT
except ValueError:
continue
def generate_integer(level: int) -> int:
# RANGE MULTI PER LEVEL
multi = [0, 1, 10, 100]
# MIN RANGE 0, 10, 100
mn = 10 * multi[level - 1]
# MAX RANGE 9, 99, 999
mx = 10 * multi[level]
return randint(mn, mx)
if __name__ == "__main__":
main()