【发布时间】:2019-10-23 13:24:35
【问题描述】:
我正在写一个基本的文字冒险游戏来练习,但是当我启动它时,无论我按什么,它都会正常打印开始,然后进入金罐部分,G加10然后结束。出于某种原因,它似乎忽略了除了 if、elif、else 语句中的第一种可能性之外还有其他可能性。任何想法为什么会这样以及我该如何解决?
start=input("Start")
if start=='yes' or 'Yes':
G=0
R=0
K=0
u=input("L/R?")
if u=='l' or 'L':
L1=input("You see a pot of gold. It has a note attached reading 'please do not take'")
if L1=='take' or 'Take':
G=G+10
else:
K=K+1
elif u=='r' or 'R':
R1=input("You see a burning pyre with a golden goblet placed in front of it. There are strange carvings on the wall")
if R1=='worship' or 'Worship':
R=R+10
elif c1=='take goblet' or 'Take goblet' or 'take' or 'Take':
R=R-5
G=G+15
else:
K=K+1
else:
sys.exit
print(G)
print(R)
print(K)
【问题讨论】:
-
条件
u == 'l' or 'L'始终为真。您可以使用u == 'l' or u == 'L'或u in 'lL'或u.lower() == 'l'。
标签: python if-statement input