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!"

Try:

import time

response=raw_input("Are you ready?\n")

while(response.lower()!="no"):
    if(response.lower()!="yes"):
        time.sleep(3)
        response=raw_input("\nAre you ready?\n")
    if(response.lower()=="yes"):
       raw_input("Let's get started!")
       break

Hope it works! :)

Comments
Thanks!

that wont work, the only problem is the while loop, what you actually want is:

import time

response=raw_input("Are you ready?\n")

while (response.lower() != "yes"):
  if (response.lower() = "no"):
    time.sleep(3)
    response=raw_input("\nAre you ready?\n")
raw_input("let's get started!")

all i did was change the loop so that you didnt need to have the code for checking if it is yes and then it will simply break to carry on

Comments
Thanks!

that wont work, the only problem is the while loop, what you actually want is:

import time

response=raw_input("Are you ready?\n")

while (response.lower() != "yes"):
  if (response.lower() = "no"):
    time.sleep(3)
    response=raw_input("\nAre you ready?\n")
raw_input("let's get started!")

all i did was change the loop so that you didnt need to have the code for checking if it is yes and then it will simply break to carry on

Mine works too, I tested it! ;)

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.

when he input N when the computer say "do you have another name"then he finish. but if he input Y then it keep repiting the question
As Integer

console.writeline("please enter you name")
name = console.readline()
Do

Loop

can someone tell me what wrong with this


If
response = raw_input("do you have another name?\n")

If (response.lower() = "Y") Then
response = raw_input("/please enter other name\n")
ElseIf response = raw_input("thank you") Then

Comments
Difficult to understand, warming up old post
This question has already been answered. Start a new discussion instead.