Under certain time I need user to input some specific sentence.
For example, user should write below sentence under 10 seconds:
Hello! World.
However, if user is unable to finish complete sentence then whatever one wrote should be accepted. So, if one is able to write only Hello! Wo
then it should be stored.
Problem - If user doesn't hit Return/Enter before time then nothing is saved. How to overcome this? Here's my approach -
import time
from threading import Thread
print('Hello! World')
user = None
def check():
time.sleep(10)
if user != None:
return
print ("Too Slow")
Thread(target = check).start()
user = input("Enter above string: \n")