title=("The Game")
print (title)
start = input("Begin?")
if start == "no" or "n":
print ("Too Bad")
import antigravity;
if start == "yes" or "y":
print ("Welcome to the Experiment")
else:
print ("IDK");无论我的回答是什么,第一个“如果”永远都是正确的。
发布于 2013-12-10 04:04:42
如果声明没有做你想做的事情。Python正在计算第一个比较,start == "no"然后将其与"n"进行比较,后者是一个非空字符串,始终是正确的。本质上是(start == "no") or "n"。
这可能就是你的意思:
if start == "no" or start == "n":但这并不是蟒蛇的方式。这就是你要找的:
if start in ["no", "n"]:这将检查start的字符串值是否在可接受的字符串值列表中。您可能还希望将小写值与类似于start.lower()的值进行比较。
https://stackoverflow.com/questions/20485734
复制相似问题