开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜