-
Notifications
You must be signed in to change notification settings - Fork 5
/
professor.py
executable file
·48 lines (43 loc) · 1.16 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
import random
def main():
level = get_level()
generate_integer(level)
def get_level():
while True:
try:
level = int(input("Level: "))
if level in [1,2,3]:
return level
except ValueError:
pass
def generate_integer(level):
counter = 3
score = 0
for i in range(10):
if level == 1:
a = random.randint(0,9)
b = random.randint(0,9)
elif level == 2:
a = random.randint(10,99)
b = random.randint(10,99)
elif level == 3:
a = random.randint(100,999)
b = random.randint(100,999)
while True:
try:
answer = input(f"{a} + {b} = ")
if int(answer) == (a+b):
score += 1
break
elif answer != (a+b):
counter -= 1
print("EEE")
if counter <= 0:
print(f"{a} + {b} = {a+b}")
break
except ValueError:
pass
else:
print(f"Score: {score}")
if __name__ == "__main__":
main()