1
Hatchling0 / 300 XP
0day streak 0stars
Your Python practice
Mock tests Readiness
More
Guest mode · saved on this device.

Project: Rock Paper Scissors

Game logic is a great fit for a function: it takes two moves and returns who won, and it is easy to test every case.

The rules: rock beats scissors, scissors beats paper, and paper beats rock. Equal moves draw.

A dict can encode those rules: beats = {"rock": "scissors", "scissors": "paper", "paper": "rock"} maps each move to the move it defeats.

See it run

beats = {"rock": "scissors", "scissors": "paper", "paper": "rock"}
move = "paper"
victim = beats[move]
print(move, "beats", victim)

One dict holds all the rules. A lookup answers "what does this move beat?"

Practice project: rock paper scissors

Exercise 1

Write winner(p1, p2) for moves "rock", "paper" and "scissors". Return "p1", "p2" or "draw".

Exercise 2

Build score_match(rounds) for a list of (p1, p2) move pairs, using the rules in Learn. Return {"p1": wins, "p2": wins, "draw": draws}. This rep starts with fresh code: define any winner helper you use in this editor, or put the decision logic inside score_match. Include all three keys even for an empty match, count every round, and leave the supplied rounds unchanged.

Exercise 3

Write champion(rounds) for a first-to-two-wins match. Draws do not earn wins. Stop as soon as either player reaches two wins, ignoring later rounds. Return "p1" or "p2" at that point; return "unfinished" if neither reaches two.

The explanation and tasks are public. Running this lesson requires an account with course access.

Practice

Loading Python…
More
Loading exercise content…
Visualizer Watch your code run line by line

Run your code, then choose Play to follow its execution.

Memory · names → values
Variables appear here as Python creates them.
Output & plots

One-line daily quest