Python Program for Rock, Paper, Scissors
Beginner · Games and random numbers
Rock, paper, scissors is a game for two players: rock beats scissors, scissors beats paper, paper beats rock, and the same choice is a draw. In this program the computer picks its move at random and plays five rounds against a list of player moves, keeping score.
Program
You: rock | Computer: rock -> Draw You: paper | Computer: scissors -> Computer wins You: scissors | Computer: rock -> Computer wins You: rock | Computer: paper -> Computer wins You: paper | Computer: rock -> You win Final score: you 1 - computer 3
How it works
random.choice(options)picks the computer move from the list, so the results change on every run.winner()checks for a draw first, then the three ways the player can win; any other pairing means the computer won.- The loop plays one round for each move in
player_movesand adds a point to whoever won that round. - Keeping the rules in one function keeps the scoring loop short and easy to read.
Another way to write it
Using a dictionary of what beats what
rock vs scissors -> You win paper vs paper -> Draw scissors vs paper -> You win
beats[player] is the one move that player defeats, so a single comparison replaces the three if checks in winner().
Try it yourself
Make the game best of three: stop as soon as either side reaches 2 points.
Edit the program above and press Run, or open it in the full editor to save it and share it. To watch it run line by line, open it in the visualizer.
For a practical file: draw its flowchart or write its algorithm in steps.
Related programs
All Python programs · CBSE class 12 practical file · Python exercises