I want to make code which stops the countdown timer when the input entered is either left or right. It's kind of similar to a gameshow where the person has a certain amount of time to answer the question. However when I try entering the input question into the code it disables the timer. What should I do?
import sys,time
def msg(txt):
sys.stdout.write(txt)
sys.stdout.flush()
for sec in range(10):
time.sleep(1)
m = "%2d" % (10-sec)
msg(m + chr(13))
print('You have been caught. Game over.')
if x == 'left':
print('you escaped')
elif x == 'right':
print('you escaped')