After a long break I'm having another foray into the world of programming in Python, and I'm really stuck with something. Loops. I think.

I think I need to use a loop for the desired effect, but I'm not sure. Basically what I want to do is this:- Ask the user a question, expecting a yes or no input- If they say yes, do one thing- If they say no, do another thing- If they input anything other than yes or no, repeat the question.

I want to loop in the sense that I want it to keep repeating the question until a sufficient answer is given. But having looked at several tutorials and online sources, I can't get my head around how to use a loop for anything more than a very basic "keep doing x until y is z", typically like this:

The problem is I don't want it to just keep doing something, I want it to actually return to an earlier point in the code, and continue from there, not do the same thing over and over. Or am I looking at this the wrong way?

while True: response = raw_input("Are you an elite hacker? ") if response.lower() == "yes": print "Can you hack a myspace for me then?!" break elif response.lower() == "no": print "Poser! Do you know anyone that is?" break else: print "Please enter a yes or no or I will keep asking the same question!"

while True: response = raw_input("Are you an elite hacker? ") if response.lower() == "yes": print "Can you hack a myspace for me then?!" break elif response.lower() == "no": print "Poser! Do you know anyone that is?" break else: print "Please enter a yes or no or I will keep asking the same question!"

Ahhh, that would appear to be exactly what I was looking for. Thanks mate!

insomaniacal wrote:I don't think you'll be able to use raw_input for that, because as soon as the script reaches "raw_input" in the code, it will stop executing the loop and wait for you to input something.

Ctrl -c will get the process to stop running, but I'm not sure I'm following what it is you're looking for. Did you want output something like this example:

>>>Enter yes or no:yesGood choice>>>Enter yes or no:noBad choice>>>Enter yes or no:maybe>>>Enter yes or no:>>>Enter yes or no:>>>Enter yes or no:>>>Enter yes or no:>>>Enter yes or no:>>>Enter yes or no:>>>Enter yes or no:>>>Enter yes or no:

so that the question will keep running until a yes or no is entered? If so, I don't see how that can be done because it's not going to accept new input until it stops running. Or am I misunderstanding you?