Week 2 Assignment

Rock Paper Scissors Game (Best of 3)

📝 Overview

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:

Expected Time: 3-4 hours
Difficulty: Easy to Medium
Recommended: Week 2 (Python Fundamentals)

đŸ“Ĩ Download Project Files

Click below to download all the files you need to get started:

đŸŽ¯ Learning Objectives

By completing this assignment, you'll be able to:

  1. Use the random module to generate unpredictable choices
  2. Use lists to store valid game options
  3. Implement game logic with conditional statements
  4. Track scores across multiple rounds
  5. Format output strings for clear presentation
  6. Create a complete, functioning game program

đŸĒœ Step-by-Step Guide

Work 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.

Step 1 — Set Up Your Variables

At the very top of rps.py (after the import), create:

  • A list called choices containing three strings: "rock", "paper", and "scissors"
  • A variable to track the player's wins, starting at 0
  • A variable to track the computer's wins, starting at 0

After this step, you should be able to run the file with no errors (even if it doesn't do anything yet).

Step 2 — Get the Player's Name

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.

Step 3 — Create the Main Game Loop

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.

Step 4 — Get the Player's Choice

Inside the loop, ask the player to enter their choice. A few things to handle:

  • Use input() to get their answer
  • Call .lower() on it so "Rock" and "ROCK" both work
  • Check if the answer is in your choices 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.

Step 5 — Generate the Computer's Choice

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.

Step 6 — Determine the Round Winner

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:

  1. First, check for a tie (both players chose the same thing)
  2. Then, check if the player won. There are 3 ways to win — write a condition for each, or combine them with or
  3. If it's not a tie and not a player win, the computer wins

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.

Step 7 — Update the Score

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.

Step 8 — Announce the Match Winner

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.

📋 Requirements Checklist

Before you're done, make sure your game does all of these:

  1. Asks for the player's name at the start
  2. Plays until someone wins 2 rounds (stops immediately at 2 — doesn't always play 3)
  3. Each round: shows choices, determines winner, updates and displays the score
  4. Accepts "rock", "Rock", "ROCK" (case-insensitive)
  5. Rejects invalid input and keeps asking until a valid choice is given
  6. Uses random.choice() for the computer's pick
  7. Uses a list to store the valid choices
  8. Announces the match winner at the end

💡 Tips for Success

  1. Run your code constantly. After every few lines, run it. Catching errors early is much easier than finding them after writing 50 lines.
  2. Read error messages carefully. Python tells you the line number where it crashed and usually describes what went wrong. Google the error message if you don't understand it.
  3. Use print() to debug. If something's not working, add print(some_variable) to see what value it actually has.
  4. Check your indentation. Python uses indentation to know what's inside a loop or if-block. One wrong indent can break everything.
  5. The cheat sheet is not cheating. Open cheat_sheet.py when you get stuck on syntax — that's what it's for.
  6. Get it working, then make it nice. First make the game work at all, then improve the messages, formatting, etc.

🎮 Example Session

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!
        

📁 Files in Your Assignment

đŸ•šī¸ Extra Credit: Hangman

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 →