import random
def validate_user_input(input):
try:
val = int(input)
except ValueError:
print("Please enter a valid input.")
return True
hidden_number = random.randint(1, 10)
user_input = ""
while user_input != hidden_number:
user_input = input("Guess the number from (1 to 1000).")
if validate_user_input(user_input) is True:
continue
else:
if int(user_input) == hidden_number:
print("You have guessed the correct number.", hidden_number)
elif int(user_input) > hidden_number:
print("You have guessed a number higher than the correct number.")
elif int(user_input) < hidden_number:
print("You have guessed a number lower than the correct number.")
else:
print("You have guessed the correct number.")
When the user has inputted the correct number I want the while function to terminate but it instead continues to loop. I tried setting a variable as true in the else function instead but that doesn't work either.
Python 3.5+