I'm trying to code a Rock, Paper, Scissors game. How do I prevent them from entering random words/letters and make them reinput their choices until they hit one of the viable choice in the Rock, Paper, Scissors game? For example: "Your input is not viable. Please try again: "
import random
def play():
user = input("Choose your secret weapon! 'Rock' or 'Paper' or 'Scissors': ")
computer = random.choice(['Rock', 'Paper', 'Scissors'])
if user == computer:
return ("It's a tie! You and computer have both chosen {}.").format(user)
if win(user, computer):
return("You've won! You chose {} and computer chose {}.").format(user, computer)
return("You've lost... You chose {} and computer chose {}.").format(user, computer)
def win(user, computer):
if(user == "Scissors" and computer == "Paper") or (user == "Paper" and computer == "Rock") or (user == "Rock" and computer == "Scissors"):
return True
return False
print(play())