1/7
Vocabulary flashcards detailing the components and logic of the Rock, Paper, Scissors input validation code.
valid_choices = ['rock', 'paper', 'scissors']
A list of the only answers allowed in the game, functioning like a rule card.
user_choice = ''
An empty box created by the computer to store the player's answer before they have typed anything.
while user_choice not in valid_choices:
A command that checks if the answer is rock, paper, or scissors, and keeps asking until a correct answer is given.
user_choice = input("Enter your choice:")
Prompts the player to make a selection and puts whatever they type into the box called user_choice.
if user_choice not in valid_choices:
A check performed by the computer to see whether the player's answer matches one of the allowed choices.
print("Invalid choice. Please try again.")
Displays an error message to the player when an incorrect or unallowed choice (such as banana) is typed.
return user_choice
Saves and gives back the correct answer for the computer to use in the game once a valid choice is typed.
Job of this code
To make sure the player chooses a valid answer before the game starts, acting like a teacher checking the answer.