Problem Set 6: rock paper scissors

When you start a new problem set, your first instinct might be to open your computer and begin typing code right away. While this can feel productive, it often leads to frustration when things don't work as expected. Instead, take a few minutes to slow down and plan.

Here are some helpful strategies:

  1. Understand the problem clearly
    • Read the instructions carefully — twice if needed.
    • Ask yourself: What exactly is being asked?
  2. Break the problem into smaller steps
    • Think about the smallest possible actions the computer will need to perform.
    • For example: If the task is to find the first recurring letter in a word, what steps must happen first?
  3. Try solving it on paper first
    • Write out your steps in plain language (pseudocode).
    • Test your steps with a simple example before touching the keyboard.
  4. Translate your steps into code
    • Start small — write only a few lines at a time and test often.
    • Don't worry about perfection at first; get a working version, then improve it.
  5. Check your solution
    • Run it with different examples, including edge cases.
    • Ask: Does this solve the problem in all situations?

  • Read the question carefully (twice).
  • Break the task into the smallest steps.
  • Sketch or write pseudocode before coding.
  • Start small — test as you go.
  • Check your solution with different cases.

Learning Objective

You will learn how to:

  • Use input and output in Python.
  • Import and use the random library.
  • Use if / elif / else statements to control the flow of a program.
  • Compare two choices and determine a winner.

 

Background

Rock, Paper, Scissors is a simple hand game:

  • Rock beats Scissors (rock crushes scissors).
  • Scissors beats Paper (scissors cut paper).
  • Paper beats Rock (paper covers rock).
  • If both players choose the same option → it’s a draw.

We will make a Python program where:

  1. The user chooses rock, paper, or scissors.
  2. The computer chooses randomly.
  3. The program compares the two choices and prints the result.

 

Tasks

Task 1: Computer Choice

Use the random module to let the computer choose between "rock", "paper", or "scissors".

import random
choices = ["rock", "paper", "scissors"]
computer = random.choice(choices)
print(computer)

Question: Run this code several times. What do you notice about the output?

 

Task 2: Player Input

Ask the user to type in their choice. Store it in a variable called player.

player = input("Choose rock, paper, or scissors: ")

Question: What happens if the user types something invalid, like "banana"?

 

Task 3: Decide the Winner

Use if / elif / else to decide the winner.

  • If both choices are the same → print "It’s a tie!".
  • Otherwise check all winning cases for the player.
  • If the player doesn’t win, the computer wins.

 

Task 4: Put It Together

Write a full program that:

  1. Asks the user for input.
  2. Randomly selects the computer’s choice.
  3. Prints both choices.
  4. Prints the result (win, lose, or draw).

Example Run:

Choose rock, paper, or scissors: rock
Computer chose: scissors
You win! Rock crushes scissors!

 

Task 5: Bonus Challenges

  1. Make the game play best of three rounds.
  2. Add a score counter for player and computer.
  3. Handle invalid inputs (e.g. if the user types "banana").
  4. Use .lower() to ignore capitalization ("Rock" and "rock" are the same).

 

Success Criteria

By the end of this task you should be able to:

  • Use random.choice() to make the computer select an option.
  • Get user input and store it in a variable.
  • Use conditional statements to decide the winner.
  • Extend the game with scoring, loops, and error handling.