Rock Paper Scissors Game (Best of 3)
In this assignment, you'll create an interactive Rock Paper Scissors game where a player competes against the computer in a best of 3 match. This project will help you practice:
random module to pick the computer's choiceClick below to download all the files you need to get started:
By completing this assignment, you'll be able to:
random module to generate unpredictable choicesWork through these steps in order. Don't try to write the whole program at once â write a little, run it, make sure it works, then move on. If something breaks, you're in the right place!
Use cheat_sheet.py if you get stuck on syntax. It has examples of every technique you need â just
adapt them to this game.
At the very top of rps.py (after the import), create:
choices containing three strings: "rock",
"paper", and "scissors"
00After this step, you should be able to run the file with no errors (even if it doesn't do anything yet).
Use input() to ask for the player's name and store it in a variable. Print a welcome message
using that name.
Test it: Run the program. It should ask for a name, print a greeting, and then stop.
The game keeps playing rounds until someone reaches 2 wins. Add a while loop after your setup
code. Your loop condition should keep the game going as long as neither player has 2 wins.
Hint: Think about what has to be true for the game to still be going. Both scores must be less than 2.
Test it: For now, put a print("Round!") inside the loop just to confirm the
loop runs. Then remove it when you're ready for Step 4.
Important: A while loop with no way to exit will run forever and freeze your
terminal. Use Ctrl+C to stop it if that happens.
Inside the loop, ask the player to enter their choice. A few things to handle:
input() to get their answer.lower() on it so "Rock" and "ROCK" both workchoices list. If it's not valid, keep asking until they give a
correct answer. You'll need a second loop for this.
Hint: You can check if something is in a list with if something in my_list. To keep asking
until valid, use a while loop with a condition like
while player_choice not in choices.
Test it: Run the program and try typing "banana". It should keep asking you to try again. Type "rock" and it should accept it.
After getting the player's choice, have the computer pick randomly. Use random.choice() and
pass it your choices list.
Then print both choices so the player can see what happened:
print(f"You chose: rock") print(f"Computer chose: scissors")
(Use your actual variables instead of the hardcoded words.)
Test it: Run a few rounds. You should see different computer choices each time.
This is the trickiest part â but break it into pieces and it's manageable. Use if / elif / else
to figure out who won the round:
or
The 3 player win conditions are: rock beats scissors, scissors beats paper, paper beats rock. Write each
one out as a comparison â for example,
player_choice == "rock" and computer_choice == "scissors".
Print a message saying who won the round and why (e.g., "rock beats scissors").
Test it: Play a round where you know what you'll pick. Verify the right winner is printed every time.
Inside your win/loss branches, add 1 to the correct score variable. After determining the winner, print the current score so the player always knows where they stand.
Example: Score: Alex 1 - Computer 0
Test it: Play multiple rounds and watch the score count up correctly.
After the while loop ends (someone reached 2 wins), print a final message announcing who won
the overall match. Use an if / else after the loop.
Test it: Play a full game. The loop should stop as soon as someone reaches 2 wins, and the final message should appear.
Before you're done, make sure your game does all of these:
random.choice() for the computer's pickprint(some_variable) to
see what value it actually has.
cheat_sheet.py when you get stuck on
syntax â that's what it's for.
Here's what a complete game could look like when it runs:
What is your name? Alex
Welcome, Alex!
--- Round 1 ---
Choose rock, paper, or scissors: rock
You chose: rock
Computer chose: scissors
You win this round! Rock beats scissors.
Score: Alex 1 - Computer 0
--- Round 2 ---
Choose rock, paper, or scissors: banana
Invalid choice. Try again: paper
You chose: paper
Computer chose: paper
It's a tie!
Score: Alex 1 - Computer 0
--- Round 3 ---
Choose rock, paper, or scissors: scissors
You chose: scissors
Computer chose: rock
Computer wins this round! Rock beats scissors.
Score: Alex 1 - Computer 1
--- Round 4 ---
Choose rock, paper, or scissors: rock
You chose: rock
Computer chose: scissors
You win this round! Rock beats scissors.
Score: Alex 2 - Computer 1
Alex wins the match!
rps.py â Your main game file (start here)
cheat_sheet.py â Reference
snippets for loops, lists, input, and random (use when you get stuck)
Finished early? Try building a Hangman game for extra credit. It uses the same skills from this project â lists, loops, and conditionals â just in a new way.
View Hangman Assignment →