I am facing an issue with the Python code below. It is supposed to execute what is in the flow chart below, but when the value is within range and wrong, the text 'Wrong! Try again. You can exit anytime by pressing Ctrl + C' never gets printed. The text 'Out of range' is being printed instead.
Below is the code I am using:
import random
from ast import literal_eval
x = random.randint(1,10)
y = 0
def f1():
if y not in range(1,11):
print('Out of range')
else:
print('Wrong! Try again. You can exit anytime by pressing Ctrl + C')
def f2():
print('Well done!')
def f3(x,y):
while x != y:
try:
y = literal_eval(input('Guess a number from 1 to 10:\n'))
if x != y:
f1()
continue
else:
f2()
break
except ValueError:
print('This is not a number')
except SyntaxError:
print('This is not a number')
except KeyboardInterrupt:
break
f3(x,y)
Any help or explanation would be very appreciated. Thank you in advance!