I'm pretty new to programming and I'm trying to create a simple card game. In the game, the player has to be able end his turn by typing 'next'. This is followed by the program sleeping for a few seconds. However, if the player types 'next' during the sleep time, the player's next turn will be skipped.
My (simplified) code:
import time
def foo():
a = input()
if str(a) == 'next':
print('next')
return
else:
foo()
return
foo()
time.sleep(5)
foo()
If you type 'next' within the five seconds of sleep, the last foo() will automatically print 'next'. How can I make the program ignore commands typed during the sleep?