- 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
randomlibrary. - 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:
- The user chooses rock, paper, or scissors.
- The computer chooses randomly.
- 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:
- Asks the user for input.
- Randomly selects the computer’s choice.
- Prints both choices.
- 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
- Make the game play best of three rounds.
- Add a score counter for player and computer.
- Handle invalid inputs (e.g. if the user types
"banana"). - 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.