I have some Python code using raw_input()
. I want to automatically go back to the raw_input if the user gives an invalid response. How do I do this?
first code:
name = raw_input("Enter Name: ")
If the user presses Enter without giving a name (which can be anything) how would I go back to raw_input?
second code:
def start():
answer = raw_input("Go outside (y,n)? ").lower()
if answer == "y":
print "I agree! We've only been here for a few days. Let's do some more exploring!"
elif answer == "yes":
print "I agree! We've only been here for a few days. Let's do some more exploring!"
elif answer == "no":
print ""
raw_input("I think we should do some more exploring; we've only been on this planet for a few days... (Press 'Enter')")
elif answer == "n":
raw_input("I think we should do some more exploring; we've only been on this planet for a few days... (Press 'Enter')")
print ""
else:
print "Press 'y' for yes and 'n' for no"
start()
I'm trying to go back to raw_input if 'else' occurs or if the user responds with "n" or "no"...