-
Notifications
You must be signed in to change notification settings - Fork 0
/
guess_the_number.py
38 lines (32 loc) · 1.2 KB
/
guess_the_number.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
# Generates a cryptographically secure number
import secrets
# SystemRandom instance from secrets module
number_generator = secrets.SystemRandom()
number = number_generator.randint(1, 10)
# The following code is used to print the generated number: print('The generated number is', number)
print('Please, guess a number between 1 and 10')
# Asks the user for input and checks if it is an integer number
while True:
try:
user_number = int(input('Your number is: '))
if 10 >= user_number >= 1:
break
print('Please, input only integer numbers between 1 and 10!')
except ValueError:
print('Please, input only integer numbers between 1 and 10!')
while number != user_number:
try:
user_number = int(input('Please, select another number!'))
if not 10 >= user_number >= 1:
print('Please, input only integer numbers between 1 and 10!')
continue
except ValueError:
print('Please, input only integer numbers between 1 and 10!')
continue
if user_number > number:
print('Too high!')
elif user_number < number:
print('Too low!')
else:
print('Awesome! The number is correct!')
break