If Statement Always True (String)

后端 未结 4 1507
悲&欢浪女
悲&欢浪女 2021-01-28 17:32

I have here a rather simple rock, paper, scissors program where I am having some trouble with if statements. For some reason, when I enter rock, paper, or scissors (True Values)

4条回答
  •  隐瞒了意图╮
    2021-01-28 18:00

    The conditions in if are wrong.

    Consider the if statement with parentheses:

    if ('rock') or ('paper') or ('scissors' not in player):
    

    It will always return True because rock will always be true.

    You need to swap conditions' operands

    if player not in computer:
    

    After this swap, this line becomes irrelevant (and also its conditions are wrong) You need to remove it:

    if player == 'rock' or 'paper' or 'scissors': 
    

提交回复
热议问题