import random
true_value = random.randint(0, 100)
while True:
guess = input('Enter your guess: ')
try:
guess = int(guess)
if guess == true_value:
print('Congratulations! You guessed correctly.')
break
elif guess > true_value:
print('Lower.') # user guessed too high
else:
print('Higher.') # user guessed too low
# when the input is invalid
except ValueError:
print('Please enter a valid number.')
Enter your guess: 50 Lower. Enter your guess: 25 Lower. Enter your guess: 13 Congratulations! You guessed correctly.