-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnum_guess.py
45 lines (34 loc) · 1010 Bytes
/
num_guess.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
import random as ra
def verify_number(entry: str) -> bool:
return entry.isdigit()
def guess_num(top, num) -> None:
print(f"I'm thinking of a number between 1 and {top}.", end=' ')
while True:
guess: str = input("Guess! ")
if verify_number(guess):
guess_int: int = int(guess)
if guess_int == 0:
print("Enter numbers above zero!")
continue
else:
print("Only enter digits!")
continue
if guess_int == num:
print("Good job!")
break
elif guess_int > num:
print("To high!")
else:
print("To low!")
def main() -> None:
while True:
top = input("Enter top of the range: ")
if verify_number(top):
num = ra.randint(1, int(top))
break
else:
print("Only enter positive digits!")
continue
guess_num(top, num)
if __name__ == "__main__":
main()