raw input - Python - loop back to raw_input if user gives an invalid response? -


this question has answer here:

i have python code using raw_input(). want automatically go raw_input if user gives invalid response. how do this?

first code:

name = raw_input("enter name: ") 

if user presses enter without giving name (which can anything) how go raw_input?

second code:

def start():         answer = raw_input("go outside (y,n)? ").lower()         if answer == "y":                 print "i agree! we've been here few days. let's more exploring!"         elif answer == "yes":                 print "i agree! we've been here few days. let's more exploring!"         elif answer == "no":                 print ""                 raw_input("i think should more exploring; we've been on planet few days... (press 'enter')")         elif answer == "n":                 raw_input("i think should more exploring; we've been on planet few days... (press 'enter')")                 print ""         else:                 print "press 'y' yes , 'n' no"  start() 

i'm trying go raw_input if 'else' occurs or if user responds "n" or "no"...

try while loop?

name = '' while not name:     name = raw_input("go outside (y,n)? ").rstrip().lower() 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -