-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.py
More file actions
36 lines (27 loc) · 670 Bytes
/
Copy pathgame.py
File metadata and controls
36 lines (27 loc) · 670 Bytes
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
from random import randint
from sys import exit
def main():
level = get_positive_int("Level: ")
number = randint(1, level)
while True:
try:
guess = get_positive_int("Guess: ")
except ValueError:
continue
if guess < number:
print("Too small!")
elif guess > number:
print("Too large!")
else:
print("Just right!")
exit()
def get_positive_int(prompt):
while True:
try:
n = int(input(prompt))
except ValueError:
continue
if n > 0:
return n
if __name__ == "__main__":
main()