【问题标题】:Python yes/no defPython 是/否定义
【发布时间】:2011-02-02 22:35:19
【问题描述】:

我正在使用下面的示例:

APT command line interface-like yes/no input?

我想按照概述将其定义为自己的定义,然后按需调用它,如下所示:

def log_manager():  
    question = "Do you wish to continue?"  
    choice = query_yes_no_quit(question, default="yes")  
        if choice == 'y':  
            print ("you entered y")  
        else:     
            print ("not working")  

无论我输入什么,总是会打印“不工作”。任何指导将不胜感激!

【问题讨论】:

  • query_yes_no_quit() 函数的返回值是多少,choice?请打印出来并更新您的问题。

标签: python prompt


【解决方案1】:

函数返回真/假。所以使用if choice:

顺便说一句,您可以通过添加print choice 自行轻松找到解决方案;)

【讨论】:

  • 谢谢!我根据你的回答整理出来的。谢谢!
【解决方案2】:

用途:

if choice:
    print("you entered y")
else:
    print("not working")

函数返回True/False,而不是"y"/"n"

【讨论】:

    猜你喜欢
    • 2013-12-24
    • 2011-09-04
    • 1970-01-01
    • 2021-05-24
    • 2022-01-08
    • 1970-01-01
    • 2013-11-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多