How to make a game in Python – Rock, Paper, Scissors

Reading Time: 2 minutes

How to make a game in Python

Rock, Paper, Scissors

rock paper scissors

Whether used as a negotiation tool for adults, or as a way to determine who gets the last slice of pizza for kids, we have all played Rock Paper Scissors. While taking a python programming course back in the day, this was the first game our teacher tasked us into creating to teach the students how to get familiar with if statements and user inputs. This is what I came up with.

The Code

How it works

First we imported the random module. Random implements pseudo-random number generators for various distributions. We set the computer to pick a random number between 0 and 2. Then we ask the user to input either rock paper or scissors and store it into a variable. Next we give the random generated number a game value using an if else statement. Lastly we set if else statements with every possible combination and print out who the winner is. Please leave a comment below if you have any recommendations on how to make the code simpler or smaller.

Download the code on Github

Interested in Learning Python?

Python Crash Course is a fast-paced, thorough introduction to Python that will have you writing programs, solving problems, and making things that work in no time.

In the first half of the book, you’ll learn about basic programming concepts, such as lists, dictionaries, classes, and loops, and practice writing clean and readable code with exercises for each topic. You’ll also learn how to make your programs interactive and how to test your code safely before adding it to a project. In the second half of the book, you’ll put your new knowledge into practice with three substantial projects: a Space Invaders–inspired arcade game, data visualizations with Python’s super-handy libraries, and a simple web app you can deploy online.


This “How to make a game in Python” blog post is located under the Programming Category



Leave a Reply

Your email address will not be published.