以下是我的节目节选:
weaponinput = input("Would you like a rifle, a pistol, or a shotgun?")
if weaponinput == " pistol":
weapon = (int(pistol_1))
if weaponinput == " rifle":
weapon = (int(rifle_1))
if weaponinput == " shotgun":
weapon = (int(shotgun_1))
if weaponinput != (" shotgun") or (" rifle") or (" pistol") or (" sniper rifle"):
print("In your futile attempt to turn",weaponinput,"into a weapon you accidentally blow your brains accross the ground.")
if
子句总是在第8行触发,不管weaponinput
的值是多少。为什么会这样?我用的是python,不太懂其他语言
你写了相当于
(2)
是非零的,因此为真。在代码中("rifle")
不是None,因此是True。你知道吗正确的形式是
另一种方法是
另一种方式:
Python会是:
您需要将该行更改为以下内容:
相关问题 更多 >
编程相关推荐