Who goes first?
Friends play one quick round to pick who starts a game.
12GAME PROJECTS · ROCK, PAPER, SCISSORS
You pick, PyBot picks at random, and a function decides who wins. Best of 3!
IN REAL LIFE
Two players choose at the same time. Clear rules say who wins.
Friends play one quick round to pick who starts a game.
One round can be luck. Three rounds and a score feel fairer.
Many games have a computer player that picks a move at random.
THE PLAN
Each step uses something you already know.
Ask the player and check the word is one of the three options.
input + or
PyBot picks one word from the list at random.
random.choice
A function compares both choices and returns the winner.
def + if/elif + and
Repeat 3 rounds and add a point to the winner each time.
for + range + counters
RUN IT
Guess first. Then run real Python and check.
for turn in range(3):
you = input("rock, paper or scissors? ")
bot = random.choice(options)PyBot's choices change each run.
How many times does the game ask you to choose?
PyBot's hint
Ready. Press Run Python.
Pyodide 314.0.3 runs CPython in your browser with WebAssembly.
Open-source under the Mozilla Public License 2.0. License
Now change one thing: Change range(3) to range(5) and write 5 answers. Now it is best of 5!
BUILD IT
PyBot fixed its choice to rock to test the game. Now every run gives the same result.
paper is a good choice, but PyBot says no. A word can't be all three at once. Fix the if.
rock, paper or scissors? paper Good choice!OUTPUT
Paper wraps rock, so paper must win. One rule in winner is wrong. Find it and fix it.
rock, paper or scissors? paper PyBot plays rock Winner: youOUTPUT
PyBot wrote 3 answers, but the game stops after 2 rounds. Make it play 3.
rock, paper or scissors? paper rock, paper or scissors? scissors rock, paper or scissors? rock Score: 1 to 1OUTPUT
YOUR TURN
Try each tiny question. A wrong answer becomes something to review.
options = ["rock", "paper", "scissors"]
bot = random.choice(options)What can be in the box bot?
if you == bot:
return "tie"You play scissors. PyBot plays scissors.
What does winner return?
elif you == "rock" and bot == "scissors":
return "you"You play rock. PyBot plays paper.
Is this elif True?
if you == "rock" or you == "paper" or you == "scissors":
print("Good choice!")
else:
print("That is not an option.")You type: lizard
What will Python show?
print(winner("scissors", "rock"))You play scissors. PyBot plays rock.
What will Python show?
your_points = 0
your_points += 1
your_points += 1
print(your_points)What will Python show?
result = winner(you, bot)
if result == "you":
your_points += 1Why does winner return a word instead of printing it?
Want a fresh start? Clear only this page.
input asks, random.choice picks, a function decides, and for repeats the rounds. Test with a fixed choice first.