AssignmentsWeek 02 · Decisions and structureChallenge — rock, paper, scissors
wk02.p9Practice exerciseWeek 02 · Decisions and structureOpen · due stretch challenge

Challenge — rock, paper, scissors

Play best-of against the computer. Combines a list of valid moves, in to check input, comparisons to decide the winner, a while loop to keep playing, and counters for the score.

What you'll build

Play best-of against the computer. Combines a list of valid moves, in to check input, comparisons to decide the winner, a while loop to keep playing, and counters for the score.

Requirements

The must-do parts. If any are missing, we'll ask you to take another pass.

  1. Keep the valid moves in a list — moves = ["rock", "paper", "scissors"].
  2. Let the computer pick with the line we give you — computer = random.choice(moves) (after import random).
  3. Ask the player for their move. If it isn't in the list, say so and ask again — use in to check.
  4. Decide the result with if / elif / else: same move is a tie, otherwise work out who wins each pairing.
  5. Use a while loop so they can play round after round, quitting when they type q. Keep a running score of wins, losses, and ties with counters.
Bonus, if you're feeling brave
  • When the game ends, print the final tally and who came out ahead overall.
  • Accept shorthand — r, p, s — as well as the full words.
  • First to 3 wins ends the match automatically.

Examples

What your program should look like when it runs. Lines starting with $ are typed by you; the rest is your program.

Example cell runs
Your move (rock/paper/scissors, or q): rock
Computer played scissors. You win!
Your move (rock/paper/scissors, or q): paper
Computer played scissors. You lose.
Your move (rock/paper/scissors, or q): banana
banana isn't a move. Try rock, paper, or scissors.
Your move (rock/paper/scissors, or q): q
Final score - wins: 1, losses: 1, ties: 0

Where to start

Copy this scaffold into a new file. You don't have to use it — it's just a friendly nudge.

# Rock, paper, scissors
import random

moves = ["rock", "paper", "scissors"]
wins = 0
losses = 0
ties = 0

# TODO: loop until the player types 'q'
#   - ask for a move; if it's not in moves, nudge and ask again
#   - computer = random.choice(moves)
#   - decide tie / win / loss with if / elif / else and update the counters
# After the loop, print the final score.

How we'll grade it

Four checks, four points. Three or above is passing — we'll ask you to revise anything we can't tick.

CheckWhat we look forPt
It runs and quitsPlays rounds and exits cleanly when the player types q. No crash on a stray input.1
Input validatedA move that isn't rock, paper, or scissors is caught with a message, not a wrong result or a crash.1
Winner logic correctEvery pairing resolves the right way, and a tie is a tie. Spot-check rock vs scissors, paper vs rock.1
Score trackedWins, losses, and ties are counted across rounds and reported at the end.1
Ready?
Hand it in
You can submit a draft and revise later if you're not done.
Begin submission →