【发布时间】:2011-11-29 05:51:20
【问题描述】:
我目前有代码:
fleechance = random.randrange(1,5)
print fleechance
if fleechance == 1 or 2:
print "You failed to run away!"
elif fleechance == 4 or 3:
print "You got away safely!"
fleechance 不断打印为 3 或 4,但我继续得到结果“你逃跑失败!” ,谁能告诉我为什么会这样?
【问题讨论】:
-
这不等同于
if fleechance == 1 or fleechance == 2。这相当于说if fleechance ==1: if 2,这将永远为真,因为if 2为真。 -
你用的是什么 Python 教程?你在哪里见过这样的代码?你能提供一个喜欢或参考吗?这段代码很糟糕,重要的是要知道你从哪里得到它可能有意义的想法。
-
我有一本书,但是我没有直接从那里得到代码,只是看起来它可以工作,所以我认为这不是教程的错。跨度>
标签: python printing random if-statement