how to use loop & time with raw_input
Hi, I'm trying to run code that asks a yes or no question. If a yes or no isn't entered, then the question will continue to re-ask say every 3 seconds until a yes or no is entered. Here's the basics of it:
while True:
response = raw_input(" Are you ready? ")
if response.lower() == "yes":
print ("Then lets get started!")
break
elif response.lower()=="no":
print ("Please try again later....")
break
else:
print ("Please enter a 'yes' or 'no' response!")
With that, I can add another while True: after the last 'else' statement but that's not exactly what I'm after. Instead, I'd like the first question "Are you ready?" to keep repeating until 'yes' or 'no' is entered. Can I somehow incorporate sleep() in this and how can I get the raw_input question to keep repeating? Example output:
>>> Are you ready? maybe
>>>Are you ready?
(3 second delay, if no answer ask again)
>>>Are you ready?
(3 second delay, if no answer ask again)
>>>Are you ready?
(3 second delay, if no answer ask again)
>>>Are you ready?yes
"Then lets get started!"
kiddo39
Junior Poster in Training
50 posts since Nov 2008
Reputation Points: 10
Solved Threads: 0
it works but not what kiddo asked for, the application that he/she wants, wants to check for keyboard inactivity and if 3 seconds passed it prints the question 'Are you ready yet' again.
baki100
Junior Poster in Training
79 posts since Apr 2009
Reputation Points: 12
Solved Threads: 14
kiddo might have to use a thread and a hook to the keyboard to get tis to go
sneekula
Nearly a Posting Maven
2,427 posts since Oct 2006
Reputation Points: 961
Solved Threads: 212
Thank you guys for your replies!
kiddo39
Junior Poster in Training
50 posts since Nov 2008
Reputation Points: 10
Solved Threads: 0