0

im using this code to make a rock paper scissors game,but im stuck on this part, i want the program to tell the player that his input is false if he inputs anything other than 'R','P'or'S', which is working but whenever i do input 'R','P'or'S' it still prints the error message "Error! Choose a valid answer(R/P/S) "

choices = ['R','P','S']
computerchoice = random.choice(choices)
print(computerchoice)

print("Let's play rock paper scissors !")
playerchoice = input("Rock paper or scissors (R/P/S)  -")
if playerchoice != ("R","P","S"):
    print("Error! Choose a valid answer(R/P/S) ")
else:
    pass 
Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
  • ```if playerchoice != ("R","P","S"):``` isn't what you think it does. It checks if playerchoice is a tuple. You want ```if playerchoice in ["R", "P", "S"]:``` or use the same tuple. – ewokx Jun 01 '22 at 23:59
  • Since you already have the variable `choices`, you can use `if playerchoice not in choices:` instead of repeating it. – Barmar Jun 02 '22 at 00:02
  • 1
    As an aside: this is **not** "a syntax bug". It is a *logical* error in the code. – Karl Knechtel Jun 02 '22 at 00:02

0 Answers0