Python yes/no def
I'm using the example below:
APT command line interface-like yes/no input?
I want to make it its own definition as outlined then call it upon demand, like this:
def log_manager():
question = "Do you wish to continue?"
choice = query_yes_no_quit(question, default="yes")
if choice == 'y':
pri开发者_StackOverflow中文版nt ("you entered y")
else:
print ("not working")
Regardless of what I input, "not working" is always printed. Any guidance would be really appreciated!
The function returns True/False. So use if choice:
Btw, you could have easily found out the solution on your own by adding print choice
;)
Use:
if choice:
print("you entered y")
else:
print("not working")
the function returns True
/ False
, not "y"
/ "n"
.
精彩评论