• <small id='nD6xv'></small><noframes id='nD6xv'>

    • <bdo id='nD6xv'></bdo><ul id='nD6xv'></ul>
    <tfoot id='nD6xv'></tfoot><legend id='nD6xv'><style id='nD6xv'><dir id='nD6xv'><q id='nD6xv'></q></dir></style></legend>

      <i id='nD6xv'><tr id='nD6xv'><dt id='nD6xv'><q id='nD6xv'><span id='nD6xv'><b id='nD6xv'><form id='nD6xv'><ins id='nD6xv'></ins><ul id='nD6xv'></ul><sub id='nD6xv'></sub></form><legend id='nD6xv'></legend><bdo id='nD6xv'><pre id='nD6xv'><center id='nD6xv'></center></pre></bdo></b><th id='nD6xv'></th></span></q></dt></tr></i><div id='nD6xv'><tfoot id='nD6xv'></tfoot><dl id='nD6xv'><fieldset id='nD6xv'></fieldset></dl></div>
      1. “或"Python 中的条件问题

        quot;orquot; conditional in Python troubles(“或Python 中的条件问题)

      2. <small id='skthQ'></small><noframes id='skthQ'>

      3. <i id='skthQ'><tr id='skthQ'><dt id='skthQ'><q id='skthQ'><span id='skthQ'><b id='skthQ'><form id='skthQ'><ins id='skthQ'></ins><ul id='skthQ'></ul><sub id='skthQ'></sub></form><legend id='skthQ'></legend><bdo id='skthQ'><pre id='skthQ'><center id='skthQ'></center></pre></bdo></b><th id='skthQ'></th></span></q></dt></tr></i><div id='skthQ'><tfoot id='skthQ'></tfoot><dl id='skthQ'><fieldset id='skthQ'></fieldset></dl></div>
              <tbody id='skthQ'></tbody>
            <legend id='skthQ'><style id='skthQ'><dir id='skthQ'><q id='skthQ'></q></dir></style></legend>
            <tfoot id='skthQ'></tfoot>

                  <bdo id='skthQ'></bdo><ul id='skthQ'></ul>
                  本文介绍了“或"Python 中的条件问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在学习 Python,但遇到了一点问题.在我正在学习的课程中看到类似的东西后想出了这个简短的脚本.我之前成功地使用了或"和如果"(这里没有显示太多).出于某种原因,我似乎无法正常工作:

                  I'm learning Python and I'm having a little bit of a problem. Came up with this short script after seeing something similar in a course I'm taking. I've used "or" with "if" before with success (it doesn't show much here). For some reason I can't seem to get this working:

                  test = raw_input("It's the flying circus! Cool animals but which is the best?")
                  x = test.lower()
                  
                  if x == "monkey" or "monkeys":
                      print "You're right, they are awesome!!"
                  elif x != "monkey" or "monkeys":
                      print "I'm sorry, you're incorrect.", x[0].upper() + x[1:], "is not the right animal."
                  

                  但这很好用:

                  test = raw_input("It's the flying circus! Cool animals but which is the best?")
                  x = test.lower()
                  
                  if x == "monkey":
                      print "You're right, they are awesome!!"
                  elif x != "monkey":
                      print "I'm sorry, you're incorrect.", x[0].upper() + x[1:], "is not the right animal."
                  

                  可能 or 条件不适合这里.但我已经尝试过,等等.我希望有一种方法可以让这个接受猴子或猴子,其他一切都会触发 elif.

                  Probably the or conditional does not fit here. But I've tried and, etc. I'd love a way to make this accept monkey or monkeys and everything else triggers the elif.

                  推荐答案

                  大多数编程语言中的布尔表达式不遵循与英语相同的语法规则.您必须对每个字符串进行单独比较,并将它们与 连接起来:

                  Boolean expressions in most programming languages don't follow the same grammar rules as English. You have to do separate comparisons with each string, and connect them with or:

                  if x == "monkey" or x == "monkeys":
                      print "You're right, they are awesome!!"
                  else:
                      print "I'm sorry, you're incorrect.", x[0].upper() + x[1:], "is not the right animal."
                  

                  你不需要对不正确的情况进行测试,只需使用else.但如果你这样做了,那就是:

                  You don't need to do the test for the incorrect case, just use else. But if you did, it would be:

                  elif x != "monkey" and x != "monkeys"
                  

                  你还记得在逻辑课上学习过德摩根定律吗?他们解释了如何反转连词或析取词.

                  Do you remember learning about deMorgan's Laws in logic class? They explain how to invert a conjunction or disjunction.

                  这篇关于“或"Python 中的条件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()(初始化多个 Numpy 数组(多重赋值) - 像 MATLAB deal())
                  How to extend Python class init(如何扩展 Python 类初始化)
                  What#39;s the difference between dict() and {}?(dict() 和 {} 有什么区别?)
                  What is a wrapper_descriptor, and why is Foo.__init__() one in this case?(什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?)
                  Initialize list with same bool value(使用相同的布尔值初始化列表)
                  setattr with kwargs, pythonic or not?(setattr 与 kwargs,pythonic 与否?)

                    <tbody id='GCWLO'></tbody>

                  <small id='GCWLO'></small><noframes id='GCWLO'>

                  • <tfoot id='GCWLO'></tfoot>
                      1. <i id='GCWLO'><tr id='GCWLO'><dt id='GCWLO'><q id='GCWLO'><span id='GCWLO'><b id='GCWLO'><form id='GCWLO'><ins id='GCWLO'></ins><ul id='GCWLO'></ul><sub id='GCWLO'></sub></form><legend id='GCWLO'></legend><bdo id='GCWLO'><pre id='GCWLO'><center id='GCWLO'></center></pre></bdo></b><th id='GCWLO'></th></span></q></dt></tr></i><div id='GCWLO'><tfoot id='GCWLO'></tfoot><dl id='GCWLO'><fieldset id='GCWLO'></fieldset></dl></div>
                        <legend id='GCWLO'><style id='GCWLO'><dir id='GCWLO'><q id='GCWLO'></q></dir></style></legend>

                          <bdo id='GCWLO'></bdo><ul id='GCWLO'></ul>