03.02 · Rock, Paper, Scissors / Learn · 18 min
Explain Rock, Paper, Scissors
The original solution prints an invalid-input warning but then continues to game_legend[user_input], which can raise KeyError. This browser adaptation puts the rest of the round inside else so invalid input stops safely. The recording remains an original reference, not a guarantee that every source line is correct.
Activity 2 of 2 in Rock, Paper, Scissors
Python Challenge Workbook / 03.02
Rock, Paper, Scissors review
Not started
Compare your approach with the original recording and an explained browser adaptation.
Your lesson progress
Empty: not started. Yellow: in progress. Green: complete. Marking the whole activity complete does not replace your test results. These circles save in this browser for this pilot.

ORIGINAL WALKTHROUGH · 17:36
Watch with Rob.
Pause whenever you want to try a change. You can return to the lesson at any time.
You are signed in, but video access needs attention. Check your account access. Your saved work is kept.
Video walkthroughs are included with an active Code Zone membership. The written lesson and practice are free.
Open video & code editor (opens in a new tab)Watch the original solution
Try the challenge before reading this review. Watch Rob’s original 17:36 solution recording above. Use theater mode to watch and code side by side, or pop out the editor into its own window. Keep your challenge editor open in another tab to compare your own approach.
Validate before dictionary lookup
The original solution prints an invalid-input warning but then continues to game_legend[user_input], which can raise KeyError. This browser adaptation puts the rest of the round inside else so invalid input stops safely. The recording remains an original reference, not a guarantee that every source line is correct.
A dictionary connects codes to labels
The supplied game_legend maps a short code such as R to Rock. Check membership in choices before looking up the full word. The tuple supplies the only three legal computer choices.
Cover all nine pairs
Handle matching moves first. Then list the three player-winning pairs. The remaining three valid unequal pairs are computer wins. Test each pair rather than assuming a single successful round proves the game is complete. Bonus: replay, reprompt on invalid moves or keep score.
One explained browser version
This is one valid approach. The challenge accepts other implementations that meet its observable game contract. Reading or copying this example does not award a pass or replace your saved work.
import random
game_legend = {"R": "Rock", "P": "Paper", "S": "Scissors"}
choices = ("R", "P", "S")
user_input = input("Choose Rock (R), Paper (P), or Scissors (S): ").strip().upper()
if user_input not in choices:
print("Invalid choice. Please choose Rock (R), Paper (P), or Scissors (S).")
else:
computer_choice = random.choice(choices)
print(f"You chose: {game_legend[user_input]}")
print(f"Computer chose: {game_legend[computer_choice]}")
if user_input == computer_choice:
print("It's a tie!")
elif (user_input == "R" and computer_choice == "S") or (user_input == "P" and computer_choice == "R") or (user_input == "S" and computer_choice == "P"):
print("You win!")
else:
print("Computer wins!")Build it one step at a time
Prefer learning by typing? Work through short instructions, run the Python code and check each change before continuing. Your guided project saves separately from the challenge below.
The mini-lesson opens in a new tab. Your own code carries forward; each step has a focused check and an optional hint.
Start mini-lesson(opens in a new tab)6 steps · Saved work · Instant feedback
Ready to try it?
Practice in your browser and see your results.
Progress details
Have a question?
Ask the Code Zone community.
Ask a question in The Code Zone (opens in a new tab)