-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofessor.py
66 lines (54 loc) · 1.33 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
import random
def main():
level = get_level()
score = simulate_game(level)
print("Score:", score)
def get_level():
while True:
try:
level = int(input("Level: "))
if level == 1 or level == 2 or level == 3 :
break
except ValueError:
pass
return level
def generate_integer(level):
if level == 1:
x = random.randint(0, 10)
y = random.randint(0, 10)
return x, y
elif level == 2:
x = random.randint(10, 50)
y = random.randint(10, 50)
return x, y
elif level == 3:
x = random.randint(50, 99)
y = random.randint(50, 99)
return x, y
def simulate_round(x, y):
tries = 1
while tries <= 3:
try:
answer = int(input(f"{x} + {y} = "))
if answer == x+y:
return True
else:
tries += 1
print("EEE")
except:
tries += 1
print("EEE")
print(f"{x} + {y} = {x + y}")
return False
def simulate_game(level):
score = 0
i = 1
while i <= 10:
x, y = generate_integer(level)
responce = simulate_round(x, y)
if responce == True:
score += 1
i += 1
return score
if __name__ == "__main__":
main()