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.
- Keep the valid moves in a list —
moves = ["rock", "paper", "scissors"]. - Let the computer pick with the line we give you —
computer = random.choice(moves)(afterimport random). - Ask the player for their move. If it isn't in the list, say so and ask again — use
into check. - Decide the result with
if/elif/else: same move is a tie, otherwise work out who wins each pairing. - Use a
whileloop so they can play round after round, quitting when they typeq. 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: 0Where 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.
| Check | What we look for | Pt |
|---|---|---|
| It runs and quits | Plays rounds and exits cleanly when the player types q. No crash on a stray input. | 1 |
| Input validated | A move that isn't rock, paper, or scissors is caught with a message, not a wrong result or a crash. | 1 |
| Winner logic correct | Every pairing resolves the right way, and a tie is a tie. Spot-check rock vs scissors, paper vs rock. | 1 |
| Score tracked | Wins, losses, and ties are counted across rounds and reported at the end. | 1 |