【问题标题】:Wrong input thrown up python [duplicate]错误的输入抛出python [重复]
【发布时间】: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


【解决方案1】:

使用

if u=='l' or u=='L':

而不是

if u=='l' or 'L':

【讨论】:

  • 解决了,谢谢。并且我修复了 R1 与 c1 混合时为自己抛出的错误
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-02-15
  • 2014-02-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-03
相关资源
最近更新 更多