【问题标题】:If statement is not working and is not making sense [duplicate]如果语句不起作用并且没有意义[重复]
【发布时间】:2021-06-02 21:42:37
【问题描述】:

我正在构建一个剪刀石头布代码,它包括 5 种选择,石头剪刀布蜥蜴和 spock。我想包括一个声明,以确保如果有人没有选择这些选项中的任何一个,它会告诉他们这是一个无效的选择并停止程序。不幸的是,我的 if 语句有问题,不管我为我的选择做了什么,它都会告诉我无效的选择并退出代码。

choice = str(input("1)Rock \n2)Paper\n3)Scissors\n4)Lizard\n5)Spock\nChoice: ")).lower().strip()

if choice != "rock" or  "paper" or "scissors" or  "lizard" or  "spock":
  print("This is an Invalid choice")
  raise SystemExit

【问题讨论】:

    标签: python if-statement logic


    【解决方案1】:

    你正在寻找这个:

    if choice not in ["rock", "paper", "scissors" ,"lizard",  "spock"]:
         print("This is an Invalid choice")
    

    【讨论】:

    猜你喜欢
    • 2013-05-26
    • 1970-01-01
    • 1970-01-01
    • 2012-12-26
    • 2013-06-20
    • 2013-09-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多