【问题标题】:I used an if-else statement and the else statement is not working [duplicate]我使用了 if-else 语句,但 else 语句不起作用 [重复]
【发布时间】:2022-11-15 22:48:56
【问题描述】:

金银岛项目:

print("Welcome to the Treasure Island.\nYour mission is to find the treasure. Good luck.")
left_or_right = input('''You are at a crossroad where do you wanna go? Type "left" or "right"\n''')
if left_or_right == "right" or "Right":
    print("You fall in a hole and die. Game over.")
else:
    swim_wait = input('''You come at a lake. There is an island in the middle of the lake.\nType "wait" to wait for a
    boat & "swim" to swim to the island''')

else 语句应该要求用户输入,但它打印的是"You fall in a hole and die. Game over."。我检查了缩进:我觉得一切都很好。问题是什么?

【问题讨论】:

    标签: python python-3.x if-statement


    【解决方案1】:

    在 if 部分,

    if left_or_right == "right" or left_or_right == "Right":
    

    那才是真正的形式 'Right' 不是布尔返回操作(只是一个字符串)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-29
      • 2023-03-13
      • 2015-05-05
      • 1970-01-01
      • 1970-01-01
      • 2011-06-09
      • 2022-01-16
      • 2014-09-15
      相关资源
      最近更新 更多