Rock, Paper, Scissors Code Explained

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/7

flashcard set

Earn XP

Description and Tags

Vocabulary flashcards detailing the components and logic of the Rock, Paper, Scissors input validation code.

8 Terms

1
New cards

valid_choices = ['rock', 'paper', 'scissors']

A list of the only answers allowed in the game, functioning like a rule card.

2
New cards

user_choice = ''

An empty box created by the computer to store the player's answer before they have typed anything.

3
New cards

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.

4
New cards

user_choice = input("Enter your choice:")

Prompts the player to make a selection and puts whatever they type into the box called user_choice.

5
New cards

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.

6
New cards

print("Invalid choice. Please try again.")

Displays an error message to the player when an incorrect or unallowed choice (such as banana) is typed.

7
New cards

return user_choice

Saves and gives back the correct answer for the computer to use in the game once a valid choice is typed.

8
New cards

Job of this code

To make sure the player chooses a valid answer before the game starts, acting like a teacher checking the answer.