I'm making a simple Python Text Adventure Game, and I want to know a way how to make a simple function that asks for a user input; however, I want the program to ONLY accept the input before a certain duration (in my program I'm using 3 seconds). Furthermore, I want the function to check the correctness of the input before accepting it as right. My attempt is as follows:
lvl1 = [
'Hi', 'Friend', 'Say', 'Smelly',
'Made', 'Tree', 'Python', 'Freak'
]
one = raw_input("You have 3 seconds to type: " + random.choice(lvl1))
endtime = time.time() + 3
while time.time() <= endtime and lvl1[0:]:
print("Wrong!")
one = raw_input("Try again: ")
print("Correct")
Basically what I want this code to do is to get an input from the user in (less than or equal to) a 3 second time duration, but before congratulating the user, make sure that their input is the same as one of the strings in the 'lvl1' array.
Thanks!