0

I'm trying to make a simple rock, paper, scissors game but I can't get my if statement to work. Currently it accepts all values but in its previous format it wouldn't accept anything. How can I make it only accept these three values and reject other ones?

def game():
    
    while True:
        playerVal = str(input("Your turn: "))#player's turn

        if playerVal == ("rock") or ("paper") or ("scissors"):
            print("success")
            compare()
            break
        else :
            print("input a correct value")
   
game()
lance
  • 11
  • 2

1 Answers1

0

This should work:

if playerVal == ("rock") or playerVal == ("paper") or playerVal == ("scissors"):

You can as well remove these brackets, I guess it's cleaner this way:

if playerVal == "rock" or playerVal == "paper" or playerVal == "scissors":

Or - in my opinion - the best way:

if playerVal in ("rock", "paper", "scissors"):

Amvix
  • 213
  • 4
  • 12