作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我的代码是这样说的:
a = input("Choose a letter")
if a == "A" or "B" or "D":
cr = "false"
elif a == "C":
cr = "true"
if cr == "false":
print("Sorry you did not asnwer correctly")
import sys
sys.exit()
elif cr == "true":
print("Well done!")
但出于某种原因,无论我输入什么,它都说它是错误的。有什么帮助吗?我是 python 新手,来自 Lua。
最佳答案
如果 a == "A"或 "B"或 "D":
其计算结果始终为 TRUE。因为“B”或“D”
每次总是评估为TRUE
。因此,无论如何,这可能归结为if 0 or 1 or 1
。
要解决此问题,您需要在每个条件运算符之后进行比较。如果a ==“A”或a ==“B”或a ==“D”
:
关于python - 如何在Python3中检查用户输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52603048/
我是一名优秀的程序员,十分优秀!