-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofessor.py
More file actions
56 lines (43 loc) · 1.21 KB
/
professor.py
File metadata and controls
56 lines (43 loc) · 1.21 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
import random
def main():
level = get_level()
score = 0
for _ in range(10):
x = generate_integer(level)
y = generate_integer(level)
correct = x + y
tries = 0
while tries < 3:
try:
answer = int(input(f"{x} + {y} = "))
if answer == correct:
score += 1
break
else:
print("EEE")
tries += 1
except ValueError:
print("EEE")
tries += 1
if tries == 3:
print(f"{x} + {y} = {correct}")
print(f"Score: {score}")
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):
if level == 1:
return random.randint(0, 9)
elif level == 2:
return random.randint(10, 99)
elif level == 3:
return random.randint(100, 999)
else:
raise ValueError("Invalid level")
if __name__ == "__main__":
main()