为什么我的 if 和 elif 结果输入不起作用?

问题描述 投票:0回答:1

无论输入中回答“否”或“是”,错误警报都是它给出的唯一答案,尽管代码描述了替代答案,但我诚实地认为编写得正确,并且我使用的程序不会给我任何错误。如果答案是“是”,我该如何让“英国人来了”提示出现,有什么帮助吗?

代码:

yes= "The british are coming"
no= "false alarm"
candle= input("Is the lantern on? ")
if no:
  print("false alarm")
elif yes:
  for i in range(10):
    print("The british are coming!")

只想制作一个带有范围函数的 if 或 elif 东西。我只是期望成为一个简单的 if 和 elif 经典双重结果。不知道出了什么问题。

python if-statement
1个回答
-1
投票

你的 if 评估表达式是错误的:

yes= "The british are coming"
no= "false alarm"
candle= input("Is the lantern on? ")
if candle=="no":
  print(no)
elif candle=="yes":
  for i in range(10):
    print(yes)
© www.soinside.com 2019 - 2024. All rights reserved.