Rock, Paper, and Scissors Game using Python Programming

Python is a super interesting and very easy-to-understand programming language. You can make cool projects with just a few lines of code. To brush up on your skill in python, you need to make projects. Whether you are a pro or a newbie doesn’t matter. You have to make projects to step up. But at the beginning of the learning phase, you can’t simply jump on a tough project. It will ruin your experience. When I was learning, this is the first project I built using python. Yes, it’s the game we play we play when we are kids. Let’s build Rock, Paper, Scissors using python.

The video tutorial of this article is here:

Rules of the Game

In the Rock, Paper, and Scissors game, only two players can participate. Each player has to pick the one(Rock, Paper, or Scissors) randomly at a time.

Rock will smash the scissors

Paper will cover the Rock

Scissors will cut the paper

Let suppose you and your best friend are playing this game. You selected Paper and Your best friend selected Rock. Then you will be the winner of the game because the paper will cover the rock. If your best friend selected paper then it will be a tie. And if the opponent selected scissors then in this case, you will lose because the scissors will cut the paper. The same conditions will go for other cases too.

You have to show the sign of the Rock, Paper, and Scissors randomly at a time using your hand. For rock you can use your fist, for the paper you can use your palm, For scissors, you can use the victory symbol using the fingers.

Execute the game

In this scenario, our opponent is our computer. So, we have to write a program for the computer. The computer has to choose between rock, paper, and scissors randomly.

Step 1:

import randommy_action = input("rock, paper or scissors?")
opponent_action = random.choice(["rock", "paper", "scissors"])

We are going to use python’s random library. In this game, we can choose only one from the available options Rock, Paper, or Scissors. We are taking our action as input. And with the help of a random library, we let the computer choose between the three options randomly.

Step 2:

print(f"My choice is: {my_action}")
print(f"Opponent Choose: {opponent_action}")

In this step, we simply print our action and the opponent's action.

Step 3:

if my_action == opponent_action:
print(f"It's a tie. Both of you selected {my_action}")
elif my_action == "rock":
if opponent_action =="scissors":
print("Rock smashes scissors.. I win!!")
print("Opponent Win!! paper covers rock")
elif my_action == "paper":
if opponent_action == "rock":
print("I win!!! paper covers rock")
print("Opponent Win!! scissors cut paper")
elif my_action == "scissors":
if opponent_action == "paper":
print("I Win!!! Scissors cut paper")
print("Opponent Win.. Rock smashes scissors")

Here are the logics we are going to use.

First, If my action and opponent’s action(computer) is equal then it’s will be a tie.

Second, If I choose “rock” and set it in my action. The computer can randomly pick one out of three options(Rock, paper, and scissors).

If the computer picks rock then it is the first case, and it will be a tie. If the computer chooses scissors then I will be the winner of the round because the rock will smash the scissors. But if the opponent's choice is paper then the opponent will be declared as the winner, because the paper will cover the rock.

The same logic goes for the paper and scissors conditions too.

If you run this code in your terminal or command prompt window, the output of the code will be something like this.

Rock, paper, and scissors game using python

Yessss..!! It’s working perfectly. It’s a fun game. You must try this.

Well, That’s it.

If this article sounds informative then make sure to follow and share it with your geek community.

Hello, My Name is Rohit Kumar Thakur. I am open to freelancing. I build react native projects and currently working on Python Django. Feel free to contact me (




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Getting Started: Composing Serverless Functions with Fission Workflows (Part 2)

How To Get BSC Wallet ?

How to extend your virtual machine diskspace (Ubuntu 16.04) (Oracle VM VirtualBox) in Windows 7

Careers in Database Technology

BPMN should be as important as typing

Why should you be writing your first Qt QML application right away?

PHP — How to break down any protocol://user:password@host:port/uri (Advanced)

Bagels Finance Public Test V2 Pool Launch Announcement

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Rohit Kumar Thakur

Rohit Kumar Thakur

More from Medium

Build a telegram bot using python in 10 min!

Image encoding

Understand Python Lists

What is Matplotlib in Python?