0

I'm building a game of "Rock, Paper, Scissors" and trying to make an "if statement" so that the game doesn't crash due to and invalid input.

I tried something like this:

Choices = input("Enter Rock, Paper or Scissors: ")
if (Choices != "Rock, Paper, Scissors"):
     print ("Please enter proper choice.")

How can I get the player to pick one of the three without this statement showing up? i.e. Player picks Rock and because it's not Paper or Scissors it prints "Please enter proper choice."

  • 1
    You need the "in" operator and a list of choices. Alternately, see [multiple comparison](https://stackoverflow.com/questions/15112125/how-to-test-multiple-variables-against-a-value). – Prune Oct 14 '20 at 21:49
  • Does this answer your question? [Asking the user for input until they give a valid response](//stackoverflow.com/q/23294658/843953) – Pranav Hosangadi Oct 14 '20 at 21:53
  • This should have been closed as duplicate of [Comparing a string to multiple items in Python](https://stackoverflow.com/q/6838238/2745495) – Gino Mempin Oct 18 '20 at 02:36

1 Answers1

2

You can use a list:

if (not Choices in ["Rock", "Paper", "Scissors"]):
    print("Please enter proper choice.")

The in keyword checks if the value is in the iterable. If Choices is not "Rock", "Paper" or "Scissors", it will print "Please enter proper choice."