From 30 to 11 Lines of Code: Rock Paper Scissors in Python

When you learn to program for the first time, you look for — or, perhaps, are assigned — projects that reinforce basic concepts. But how often do you, once you’ve attained more knowledge and experience, revisit those beginner projects from the perspective of an advanced programmer?

In this article, I want to do just that. I want to revisit a common beginner project — implementing the game “Rock Paper Scissors” in Python — with the knowledge I’ve gained from nearly eight years of Python programming experience.

The Rules Of “Rock Paper Scissors”

Before diving into code, let’s set the stage by outlining how “Rock Paper Scissors” is played. Two players each choose one of three items: rock, paper, or scissors. The players reveal their selection to each other simultaneously and the winner is determined by the following rules:

  1. Rock beats scissors
  2. Scissors beats paper
  3. Paper beats rock

Growing up, my friends and I used “Rock Paper Scissors” to solve all sorts of problems. Who gets to play first in a one-player video game? Who gets the last can of soda? Who has to go pick up the mess we just…