-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLittle Professor
More file actions
50 lines (42 loc) · 1.12 KB
/
Little Professor
File metadata and controls
50 lines (42 loc) · 1.12 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
import random
def get_level():
while True:
try:
level = int(input("Level: "))
if level in [1, 2, 3]:
return level
except ValueError:
continue
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")
def main():
level = get_level()
score = 0
for _ in range(10):
x = generate_integer(level)
y = generate_integer(level)
answer = x + y
attempts = 0
while attempts < 3:
try:
user_input = int(input(f"{x} + {y} = "))
if user_input == answer:
score += 1
break
else:
print("EEE")
except ValueError:
print("EEE")
attempts += 1
if attempts == 3:
print(f"{x} + {y} = {answer}")
print("Score:", score)
if __name__ == "__main__":
main()