开发者

Python yes/no def

开发者 https://www.devze.com 2023-02-08 00:34 出处:网络
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:

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

精彩评论

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

关注公众号