Python Game Design: Rock, Paper, Scissors
CAD

Python Game Design: Rock, Paper, Scissors

Grades 3–8
2 hr 8 min
10 steps
NC CTEKindergarten through Grade 5Grade 6 through Grade 8

Standards Alignment

NC CTE

Game Design and Development (8400/ 36 weeks)

  • GDD.1.1: Demonstrate creativity and innovation.
  • GDD.1.2: Demonstrate critical thinking and problem solving.
  • GDD.15.88: Create games.
  • GDD.3.13: Demonstrate continuous learning and adaptability.

NC CTE

Computer Systems Technology 1 (8622)

  • CST1.1.2: Demonstrate critical thinking and problem solving.
  • CST1.2.6: Demonstrate conflict-resolution skills.
  • CST1.1.1: Demonstrate creativity and innovation.

Kindergarten through Grade 5

  • E.AP.1A: Create clearly named variables representing different data types and perform operations on the variables’ values.
  • E.AP.4A: Create a simple program to achieve a goal with expected outcomes.
  • E.AP.2A: Define what a control structure is and create programs that include sequences, conditionals, events, and loops.
  • E.AP.4B: Test and debug a program or algorithm to ensure the program produces the intended outcome.
  • E.AP.3B: Modify, remix, or incorporate parts of an existing problem’s solution to develop something new or add more advanced features to a program.

Showing 12 of 16 standards.

Lesson Steps

1

👋 Welcome to Python Game Design!

3 min

 

What is Python?

 

Python is a programming language used throughout the world. People like Python because of its ease of use and its power. We will use Python to create games that you can actually play and enjoy!

Here’s a quick guide for   Python syntax  (how to code in the Python language). You may find this helpful as you program your project.

 

 

Now you’re ready to code! Open a new tab or window to follow along with our myBetabox videos. Then, click on the next section to start!

Teaching tips

Overview: Students will use the Python programming to code a variety of mini games with the Repl.it platform.

Time: About 1-3 class periods per project; can be completed at your own pace.

Programming Languages: Python

Programs and Software Used:

 

What's Covered?

  • Conditionals
  • If/then statements
  • Elif (else/if)
  • Print
  • Packages
  • Refactoring
  • Variables
  • Boolean and While loops
  • Concatenation and strings
  • String formatting
  • Lists
  • Constant variables
  • Functions
  • Newline characters
  • Inputs and curly brackets

Lesson Steps

  1. Have students read the following sections:
    1. Welcome to Python Game Design!
    2. Setting VS Code
    3. Setting up Repl.it
    4. Keyboard Guide
  2. Guide your students into creating their Repl.it accounts. They may need to verify their accounts in their emails. Once they have them set up, they can share their progress with you.
  3. Introduce the VS Code tools and interface in Setting Up VS Code
  4. Check for understanding on how to type the symbols in the Keyboard Guide.
  5. If you'd like, you can print out our Python cheat sheet and distribute to your students for their reference. This is also found in their Welcome to Python Game Design! section.
  6. Review the section vocabulary below.

Vocabulary

  • Code: Instructions that tells a computer or computer program what to do.
  • Verify: To prove.
  • Interface: The area where a user can interact with the computer, usually by clicking or typing.
  • Syntax: The format, or way, code typed. Syntax is different for different languages.
2

⌨️ Keyboard Guide

4 min

Here are some handy guides for coding symbols. Hold the keys with a circle down at the same time.

 

Keyboard Guide

 

Tab = used for indenting lines

 

 

 : Colon = Shift + ; 

 

 

_ Underscore = Shift + -

 

 

( Left Parenthesis = Shift + 9

 

 

) Right Parenthesis = Shift + 0

 

 

[ Left Bracket

 

 

] Right Bracket

 

 

" Quotation Marks

 

 

\ Backslash

Teaching tips

Lesson Steps

  1. Have students read the following sections:
    1. Welcome to Python Game Design!
    2. Setting Up VS Code
    3. Setting up Repl.it
    4. Keyboard Guide
  2. Guide your students into creating their Repl.it accounts. They may need to verify their accounts in their emails. Once they have them set up, they can share their progress with you.
  3. Introduce the VS Code tools and interface in Setting Up VS Code.
  4. Check for understanding on how to type the symbols in the Keyboard Guide.
  5. If you'd like, you can print out our Python cheat sheet and distribute to your students for their reference. This is also found in their Welcome to Python Game Design! section.
  6. Review the section vocabulary below.

Vocabulary

  • Code: Instructions that tells a computer or computer program what to do.
  • Verify: To prove.
  • Interface: The area where a user can interact with the computer, usually by clicking or typing.
  • Syntax: The format, or way, code typed. Syntax is different for different languages.
3

💻 Setting Up VS Code

15 min

VS Code Set Up

 

 

What is VS Code?

 

VS Code (Visual Studio Code) is a powerful, free, and open-source source code editor. It provides a user-friendly environment for writing, editing, and debugging code across multiple programming languages.

Unlike Repl.it, which is a web-based coding platform, VS Code is a desktop application that you can install on your computer. It offers more advanced features and customization options, making it a popular choice among developers and programmers.

To download for free, simply go to the VS Code download page on their website. 

 

 

 

VS Code Interface

 

  1. Interface Overview: When you open VS Code, you’ll see a clean and organized interface. The main window consists of a sidebar on the left, an editor area in the center, and a status bar at the bottom. The sidebar provides quick access to files, folders, and extensions. The editor area is where you write your code, and the status bar displays useful information like the terminal and errors for debugging.

  2. Creating and Opening Files: To create a new file, click on the “File” menu at the top-left corner and select “New File.” You can then start typing your code in the editor area. To open an existing file, go to “File” and choose “Open File” or “Open Folder.” Navigate to the location of your file or folder, select it, and click “Open.”

  3. Installing the Python Extension: The Python extension is a helpful tool that adds Python-specific features to VS Code. To install it, follow these steps:

 

 

 

  • Click on the square icon with four squares on the left sidebar (Extensions).
  • In the search bar at the top, type “Python.”
  • Look for the official Python extension by Microsoft and click “Install.”
  • Once installed, you’ll be able to see this play button at the top right when you open up a new text file and start writing code:

     

 

 

Using VS Code for Python Game Design: To create a Python game in VS Code, follow these general steps:

  • Start by creating a new Python file (or open an existing one).
  • Import any necessary libraries or modules for game development.
  • Write your code to design the game mechanics, graphics, and interactions.
  • Utilize loops, conditional statements, and functions to control the game’s behavior.
  • Test your game by running the code.
  • Debug and troubleshoot any issues using the debugging features of VS Code.

Teaching tips

Lesson Steps

  1. Have students read the following sections:
    1. Welcome to Python Game Design!
    2. Setting Up VS Code
    3. Setting up Repl.it
    4. Keyboard Guide
  2. Guide your students into creating their Repl.it accounts. They may need to verify their accounts in their emails. Once they have them set up, they can share their progress with you.
  3. Introduce the VS Code tools and interface in Setting Up VS Code.
  4. Check for understanding on how to type the symbols in the Keyboard Guide.
  5. If you'd like, you can print out our Python cheat sheet and distribute to your students for their reference. This is also found in their Welcome to Python Game Design! section.
  6. Review the section vocabulary below.

Vocabulary

  • Code: Instructions that tells a computer or computer program what to do.
  • Verify: To prove.
  • Interface: The area where a user can interact with the computer, usually by clicking or typing.
  • Syntax: The format, or way, code typed. Syntax is different for different languages.
4

⚙️ Setting Up Repl.it

15 min

Repl.it Set Up

 

 
 

What is Repl.it?

 

Repl.it is the website that we will be using to code our game. This will prevent us from having to download anything such as Python or an IDE and will allow us to easily share our projects!

To use Repl.it, simply go to www.repl.it and click sign up in the top right of the site. Once you have set up your free account, we can start exploring the interface!

 

 

 

Repl.it Interface

 

The first step to coding on Repl.it is creating a new repl, which stands for…

  • Read (computer reads the code you typed)
  • Evaluate (runs the code)
  • Print (shows the results)
  • Loop (does R, E, and P in a loop)

Think of it repls like coding projects. You should notice a button on the top right that says ‘+ new repl.’

 

When you click this button, you will be asked what programming language you want to use. For now, we are simply going to click on Python and name it whatever you would like!

 

 

Now that our repl has been created we can see the coding interface. The far left of the screen is our file directory and will tell us what files and folders are in our project.

 

 

The middle section is our workspace where we will type our code…

 

 

…and the far right section is where we will see our code when we click run!

 

 

 

The other important part of this screen is the share button. This button will allow you to share your code with others in case you get stuck!

 

Teaching tips

Lesson Steps

  1. Have students read the following sections:
    1. Welcome to Python Game Design!
    2. Setting Up VS Code
    3. Setting up Repl.it
    4. Keyboard Guide
  2. Guide your students into creating their Repl.it accounts. They may need to verify their accounts in their emails. Once they have them set up, they can share their progress with you.
  3. Introduce the VS Code tools and interface in Setting Up VS Code.
  4. Check for understanding on how to type the symbols in the Keyboard Guide.
  5. If you'd like, you can print out our Python cheat sheet and distribute to your students for their reference. This is also found in their Welcome to Python Game Design! section.
  6. Review the section vocabulary below.

Vocabulary

  • Code: Instructions that tells a computer or computer program what to do.
  • Verify: To prove.
  • Interface: The area where a user can interact with the computer, usually by clicking or typing.
  • Syntax: The format, or way, code typed. Syntax is different for different languages.
5

👊 Rock, 🤚Paper, or ✌️ Scissors?

20 min

Rock, Paper, Scissors is probably one of the first games you learned how to play with parents or friends! We will be creating our own version of the game where we play against the computer today!

Let’s start by creating a simple version that will allow us to play one round of the game and then we can add on to it and make the program keep score!

Keyboard Guide

 

Rock, Paper, or Scissors?


 

Stuck? Copy & Paste the Code into Repl.it or VS Code

 

import random

player_wins = 0
comp_wins = 0

print("Welcome to RPS")
player_choice = input("Do you pick [rock], [paper], or [scissors]?: ")

comp_choice = random.choice(["rock", "paper", "scissors"])

print("Player chose " + player_choice + " and Computer chose " + comp_choice)

 

How it looks on VS Code:

 

 


 

The Code Explained

 

First, we will need the computer to be able to make random choices for us. To do this we need to import something called a package.

 

🌟 A package is a collection of pre-written code that will make our time programming much easier.

 

To import this package, simply type the following at the top of your file:

 

import random

 

Now that we have imported the package we can start using it to make random choices for the computer!

Next, let’s code a way to record the number of times a player and the computer wins a round. We can do this by coding a variable that will store this info.

 

🌟 A variable stores information and values such as characters (letters/words/symbols), numbers, and booleans (true/false statements). Variables can change.

 

Since we haven’t played any matches yet, let’s set the number of wins for both to 0.

 

player_wins = 0
comp_wins = 0

 

Whenever we want the game to say something for the player to see, we will tell the program to print. We want to print a greeting in the form of a string inside quotation marks.

 

🌟 Print sends text, variables, and other objects to the screen for the user to see.

 

🌟 A string is a sequence of characters (numbers, letters, symbols and spaces) and start and end with quotation marks. In this example, the string is “Welcome to RPS”, including the spaces between words.

 

print("Welcome to RPS")

 

Now we need to ask the player what they want to choose and save it in a variable so that we can use it later.  Input is the function we’ll use to interpret user choices.

 

🌟 Functions are packets of code that do a certain task and are always followed by ( ). Functions we use in this section are print(), input(), and random.choice().

 

To do this we will type the following code on the next line:

 

player_choice = input("Do you pick [rock], [paper], or [scissors]?: ")

 

It is important to note that I put a space after the colon. I did this so that when we type our answer it will not start right at the colon.

Once we have saved the player input, we need to randomly decide what the computer is going to pick. To do this, we use a function from the random package called choice. Take a look at the following code to see how it works:

 

comp_choice = random.choice(["rock", "paper", "scissors"])

 

This function takes a list, which is a group of items contained in square brackets, and randomly chooses an item from it.  These will be the options the computer can choose from. In this case, our list is [“rock”, “paper”, “scissors”].

 

🌟 Lists can contain several things including numbers, strings, variables, and Booleans. Lists use square brackets [ ] and list items are separated by commas.

 

Now let’s display which choices the player and the computer made. To see them, we need to print them to the screen. We will concatenate a string using these choices.

 

🌟 Concatenation is smushing two strings together as they are written.

 

print("Player chose " + player_choice + " and Computer chose " + comp_choice)

Teaching tips

Let's get started by importing the random library, setting up variables, and setting up game choices.

Lesson Steps

  1. Have students navigate to the Rock, Paper, or Scissors? section.

  2. Students should have another tab or window open with their Repl.it projects open so they can follow along with the videos.
  3. If they get stuck, there is code beneath they videos they can copy and paste into Repl.it but encourage them to practice typing out the code on their own. Note: Keep in mind that copy/pasting the code will replace any customized strings, variables etc...
  4. Point out the Keyboard Guide link at the top of every page if they need.
  5. Encourage students to read The Code Explained subsection below. Nearly all student-side sections will have information under the videos to help explain the code they are using as well as tips and analogies.
  6. Check for understanding and answer any questions they may have before moving on to the next section.
  7. Review the section vocabulary below.

Vocabulary

  • Import: To take file(s) from one location to the program or software you're using.
  • Package: A collection of pre-written code that will make our time programming much easier.
  • Variable: Code that stores information and values such as characters (letters/words/symbols), numbers, and booleans (true/false statements). Variables can change.
  • Function: Packets of code that do a certain task and are always followed by () in Python. Functions we use in these first sections are print(), input(), and random.choice().
  • Print: A function that sends text, variables, and other objects to the screen for the user to see.
  • String: A sequence of characters (numbers, letters, symbols and spaces) and start and end with quotation marks.
  • List: Code that contains several things including numbers, strings, variables, and Booleans. Lists use square brackets [ ] and list items are separated by commas.
  • Concatenation: Combining two or more strings together as they are written using +.
    • Joining the two strings "I love my" + "cat" creates "I love mycat"
    • Joining the two strings "I love my " + "cat" creates "I love my cat"
6

⭐ Coding the Winning and Losing Scenarios

20 min
Keyboard Guide

Coding the Winning and Losing Scenarios

 


 

Stuck? Copy & Paste the Code into Repl.it

 

import random

player_wins = 0
comp_wins = 0

print("Welcome to RPS")
player_choice = input("Do you pick [rock], [paper], or [scissors]?: ")

comp_choice = random.choice(["rock", "paper", "scissors"])

print("Player chose " + player_choice + " and Computer chose " + comp_choice)

if player_choice == "rock" and comp_choice == "scissors":
  print("You Won! Congratulations!")
  player_wins += 1
elif player_choice == "paper" and comp_choice == "rock":
  print("You Won! Congratulations!")
  player_wins += 1
elif player_choice == "scissors" and comp_choice == "paper":
  print("You Won! Congratulations!")
  player_wins += 1
elif player_choice == "rock" and comp_choice == "paper":
  print("You Lost! Try Again!")
  comp_wins += 1
elif player_choice == "paper" and comp_choice == "scissors":
  print("You Lost! Try Again!")
  comp_wins += 1
elif player_choice == "scissors" and comp_choice == "rock":
  print("You Lost! Try Again!")
  comp_wins += 1
elif player_choice == comp_choice:
  print("You Tied! Try Again!")

 


 

The Code Explained

 

Now that both players have entered their answer, we can compare to see who won! This is the most complicated part because it uses conditionals to check to see who won. In Python, we use == to compare two things in conditionals.

 

🌟 Conditionals are ‘if’ statements that compare two values. If statements always have a : at the end.

 

Take a look at the below code for an example of how our comparisons will work:

IF I use rock against scissors THEN I win.

 

if player_choice == "rock" and comp_choice == "scissors":
  print("You Won! Congratulations!")
  player_wins += 1

 

This if statement checks to see if your answer was rock and the computer’s answer was scissors. If that statement is true then it will print out the congratulations message!

We also added 1 point to the score by incrementing the player_wins variable under that condition.

 

🌟 Incrementing is adding to a number. You can add 1 to a number by using += 1.

 

You may have noticed that some of the lines are indented, or starting after a couple spaces to the right. This is because of Python syntax for conditionals. If your final code isn’t working, make sure the lines that need to be indented are! You can so this by pressing tab on your keyboard.

Now, what about the other results? Let’s start by adding the rest of the winning conditions using an elif as you see below:

 

🌟 Elif stands for else if and is used to make outcomes for more scenarios.

 

elif player_choice == "paper" and comp_choice == "rock":
  print("You Won! Congratulations!")
  player_wins += 1

 

This conditional uses elif which stands for else if. This once again checks for a win condition and prints out the congratulations message if it is true. Make sure to notice that the print statement and player_wins are indented from the if statement. Python requires you to do this so do not forget it! Now you can write your last win conditional!

 


 

After writing all the win conditions, we need to write the loss conditions. They will look very similar but will have different messages. Take a look at this example:

 

elif player_choice == "rock" and comp_choice == "paper":
  print("You Lost! Try Again!")
  comp_wins += 1

 

Now that you have an idea of how to write the loss condition, go ahead and write the other two losing conditions as well before we move on!

We also need to look out for two other conditions. One of them is a tie. We can check for a tie by doing the following:

 

elif player_choice == comp_choice:
  print("You Tied! Try Again!")

 

The other option is that the player did not put in a valid answer because it wasn’t typed correctly or they used a completely different word. If this happens we need to tell them that they did not give a valid answer. You can do something like the following:

 

else:
  print("That's not an option and you know it!")

 

With that final line of code, we have a game that will work! Feel free to give it a shot and report back!

Teaching tips

Now we will use else/if statements to program all the possible winning and losing combinations there are in a standard Rock, Paper, Scissors game.

Lesson Steps

  1. Have students navigate to the Coding the Winning and Losing Scenarios section.

  2. Explain that elif statements stand for else/if conditions and direct the computer how to check for what to do in any given scenario.
  3. Invite students to think of and discuss some examples of elifs.
    • IF: If I have pink pens then I will draw a balloon...
    • ELIF: else (if I don't have pink) if I have blue pens then I will draw a blueberry...
    • ELIF: else (if I don't have pink or blue) if I have green pens then I will draw a tree...
    • ELSE: else (I don't have pink, blue nor green) I will read a book instead.
  4. Check for understanding and answer any questions they may have before moving on to the next section.
  5. Review the section vocabulary below.

Vocabulary

  • Conditional Statements: ‘If’ statements that compare two values. If statements always have a : at the end.
  • Increment: To add by 1, as in a score.
  • Elif: Conditionals that direct the computer how to check for what to do in any given scenario.
7

🔁 Loop to Replay

20 min
Keyboard Guide

Loop to Replay

 


 

Stuck? Copy & Paste the Code into Repl.it

 

import random

player_wins = 0
comp_wins = 0

playing = True

while playing:
  print("Welcome to RPS")
  player_choice = input("Do you pick [rock], [paper], or [scissors]?: ")

  comp_choice = random.choice(["rock", "paper", "scissors"])

  print("Player chose " + player_choice + " and Computer chose " + comp_choice)

  if player_choice == "rock" and comp_choice == "scissors":
    print("You Won! Congratulations!")
    player_wins += 1
  elif player_choice == "paper" and comp_choice == "rock":
    print("You Won! Congratulations!")
    player_wins += 1
  elif player_choice == "scissors" and comp_choice == "paper":
    print("You Won! Congratulations!")
    player_wins += 1
  elif player_choice == "rock" and comp_choice == "paper":
    print("You Lost! Try Again!")
    comp_wins += 1
  elif player_choice == "paper" and comp_choice == "scissors":
    print("You Lost! Try Again!")
    comp_wins += 1
  elif player_choice == "scissors" and comp_choice == "rock":
    print("You Lost! Try Again!")
    comp_wins += 1
  elif player_choice == comp_choice:
    print("You Tied! Try Again!")

  print("Player Wins: " + str(player_wins) + " - Computer Wins: " + str(comp_wins))

  stop = ""

  while stop not in ["y", "n"]:
    stop = input("Would you like to stop playing? [y]/[n]?: ")

  if stop == "y":
    playing = False
    print("Thank you for playing")

 

 


 

The Code Explained

 

You have probably noticed that we have to run the program every time we want to play a round. What if we want to play multiple rounds and keep track of the score? We can change our code to do just that! This is called refactoring and programmers do it all the time to add new functionality to their code and to clean it up.

We need to create a variable to let our game know that we want to keep playing!

 

🌟 Keep in mind to capitalize your True and False (Boolean) statements otherwise the code will not work.

 

playing = True

 

Now that we have these three variables set up, we can introduce the while loop. A while loop will continuously run through code while a value is true.

Think of it like your refrigerator. While the fridge door is open, the light stays on. Does the light stay on if the door is closed?

To use a while loop we need to put all over our previous code inside it, like an umbrella. Do this by tabbing each line of code.

 

  • All of the player_wins/comp_wins/prints should line up.
  • All of the if/elif statements should line up with each other.

 

This will allow our previous code to run forever. If you start the game now, you will see that the game loops forever. We aren’t finished yet though! 

Now we need to display that score after every match. To do this, we will add code inside of our while loop but outside of our last conditional! It should look something like this:

 

print("Player Wins: " + str(player_wins) + " - Computer Wins: " + str(comp_wins))

 

This line will display how many wins you have and how many wins the computer has. You may notice that this line has plus signs in it. This allows us to glue multiple pieces of texts and variables together into one line and is known as concatenation. We also have to use the str() function to change our numbers into strings because that is the only way they can be concatenated!

Now we simply need to add a few more lines of code that will allow the user to quit the game if they want. We should now ask if the player wants to quit and let them quit if they do. The following code will help us do that:

 

 stop = ""

  while stop not in ["y", "n"]:
    stop = input("Would you like to stop playing? [y]/[n]?: ")

  if stop == "y":
    playing = False
    print("Thank you for playing")

 

After adding this code, you will be able to run your game and see your creation!

Teaching tips

See how the game runs as it is. Then, write code allowing the player to keep playing rounds of RPS without having to run the program each time.

Lesson Steps

  1. Have students navigate to the Loop to Replay section.

  2. Your students can do an optional activity to understand while loops and Boolean statements.
    • Students will take turns playing RPS against other students with their hands.
    • Starting with two students (A and B), have A declare, "While I win rounds, I can keep playing."
    • Students A and B play one round of RPS.
    • If student A wins, have them say, "This statement is true!" and they can move onto the next person in line and repeat their lines.
    • If student A loses or ties, have them say, "This statement is false!" Student B replaces student A and continues down the line.
  3. Check for understanding and answer any questions they may have before moving on to the next section.
  4. Review the section vocabulary below.

Vocabulary

  • Refactoring: Improving and restructuring existing code to make the product run smoothly.
  • Boolean: In programming terms, a way to see if something is true or false.
  • While Loop: A repeating line of code that continuously runs while a value is true.
8

🐞 Fixing Bugs

15 min

Fixing Bugs

 

 

 

Stuck? Copy & Paste the Code into Repl.it

 

import random

player_wins = 0
comp_wins = 0

playing = True

while playing:
  print("Welcome to RPS")
  player_choice = input("Do you pick [rock], [paper], or [scissors]?: ").lower()

  while player_choice not in ["rock", "paper", "scissors"]:
    print("That isn't an option, try again!")
    player_choice = input("Do you pick [rock], [paper], or [scissors]?: ").lower()

  comp_choice = random.choice(["rock", "paper", "scissors"])

  print("Player chose " + player_choice + " and Computer chose " + comp_choice)

  if player_choice == "rock" and comp_choice == "scissors":
    print("You Won! Congratulations!")
    player_wins += 1
  elif player_choice == "paper" and comp_choice == "rock":
    print("You Won! Congratulations!")
    player_wins += 1
  elif player_choice == "scissors" and comp_choice == "paper":
    print("You Won! Congratulations!")
    player_wins += 1
  elif player_choice == "rock" and comp_choice == "paper":
    print("You Lost! Try Again!")
    comp_wins += 1
  elif player_choice == "paper" and comp_choice == "scissors":
    print("You Lost! Try Again!")
    comp_wins += 1
  elif player_choice == "scissors" and comp_choice == "rock":
    print("You Lost! Try Again!")
    comp_wins += 1

  print("Player Wins: " + str(player_wins) + " - Computer Wins: " + str(comp_wins))

  stop = ""

  while stop not in ["y", "n"]:
    stop = input("Would you like to stop playing [y]/[n]?: ").lower()

  if stop == "y":
    playing = False
    print("Thank you for playing!")

 


 

The Code Explained

 

What happens if I type something that’s not rock, paper, or scissors…like spaghetti?

 

You can program your game to say something when a player types a word not found in the list of valid selections. Then the game will repeat the original question.

 

 while player_choice not in ["rock", "paper", "scissors"]:
    print("That isn't an option, try again!")
    player_choice = input("Do you pick [rock], [paper], or [scissors]?: ")

 

 

I typed Rock/Paper/Scissors but it didn’t work!

 

If you coded your game with rock but typed Rock, ROCK, rOcK, etc… the computer won’t recognize those as valid entries. Think of it like training your dog to sit. Your pup has practiced and learned to sit when you say “Sit!” but it won’t understand if you say “squat” or “stay put” even it they mean the same to you.

 

 

Is there a way to make words with random capitalization work?

 

Yes! Add a lower() function at the end of your player_choice = input function to turn all typed choices automatically into lowercase. So even if someone types RoCK, and you coded your game with rock, then it will work.

 

player_choice = input("Do you pick [rock], [paper], or [scissors]?: ").lower()

Teaching tips

Common student questions, errors, and how to address them.

Lesson Steps

  1. Have students navigate to the Fixing Bugs section.

  2. If students are having trouble self-correcting coding mistakes, see what they are doing with the share feature.
  3. Check for understanding and answer any questions they may have before moving on to the next section.
9

🎉 Customization

15 min

Customization (2 videos)

 

 

 


 

Stuck? Copy & Paste the Code into Repl.it

 

import random

player_wins = 0
comp_wins = 0
ties = 0

playing = True

while playing:
  print("Welcome to RPS")
  print("This is a text version of the popular game.")
  print("Play by typing in either rock, paper, or scissors when prompted.")
  print("Rock crushes scissors, paper covers rock, and scissors cuts paper.")
  player_choice = input("Do you pick [rock], [paper], or [scissors]?: ").lower()

  while player_choice not in ["rock", "paper", "scissors"]:
    print("That isn't an option, try again!")
    player_choice = input("Do you pick [rock], [paper], or [scissors]?: ").lower()

  comp_choice = random.choice(["rock", "paper", "scissors"])

  print("Player chose " + player_choice + " and Computer chose " + comp_choice)

  if player_choice == "rock" and comp_choice == "scissors":
    print("You Won! Congratulations!")
    player_wins += 1
  elif player_choice == "paper" and comp_choice == "rock":
    print("You Won! Congratulations!")
    player_wins += 1
  elif player_choice == "scissors" and comp_choice == "paper":
    print("You Won! Congratulations!")
    player_wins += 1
  elif player_choice == "rock" and comp_choice == "paper":
    print("You Lost! Try Again!")
    comp_wins += 1
  elif player_choice == "paper" and comp_choice == "scissors":
    print("You Lost! Try Again!")
    comp_wins += 1
  elif player_choice == "scissors" and comp_choice == "rock":
    print("You Lost! Try Again!")
    comp_wins += 1
  elif player_choice == comp_choice:
    print("You Tied! Try Again!")
    ties += 1

  print("Player Wins: " + str(player_wins) + " - Computer Wins: " + str(comp_wins) + " - Ties: " + str(ties))

  stop = ""

  while stop not in ["y", "n"]:
    stop = input("Would you like to stop playing [y]/[n]?: ").lower()

  if stop == "y":
    playing = False
    print("Thank you for playing!")

 


 

The Code Explained

 

Now it’s time for you to switch up some elements in your game!

 

Make the game something other than Rock, Paper, Scissors!

 

If you want to make your game about something else, like animals (bird, turtle, dog), then replace those words in your game. Make sure your elif conditions make sense when changing it up.

 

Add ties to the score keeper!

 

First add a ties variable to keep track of the number of ties in your game.

 

ties = 0 

 

Next, increment the tied score value if the player_choice is the same as the comp_choice.

 

elif player_choice == comp_choice:
    print("You Tied! Try Again!")
    ties += 1

 

Then, add and concatenate strings to the score tracker.

 

print("Player Wins: " + str(player_wins) + " - Computer Wins: " + str(comp_wins) + " - Ties: " + str(ties))

 

Write more game messages!

 

Use the print() function to create more in-game messages. You can write anything from instructions, backstories, or fun facts. Remember to use quotation marks inside the parentheses when writing sentences for strings.

 

print("Rock crushes scissors, paper covers rock, and scissors cuts paper.")

Teaching tips

Now that we've coded the framework for Rock, Paper, Scissors we can customize the game even further!

Lesson Steps

  1. Have students navigate to the Customization section.

  2. After they watch the videos and read the sections, invite them to change up their code using a variety of customization methods including:
    • Changing point values
    • Make rock, paper, and scissors something else
    • Print various in-game messages
    • ...and more!
  3. Check for understanding and answer any questions.
  4. Have students share their projects with you and each other. This is a good opportunity for students to beta test each other's work and provide feedback.
10

🐍 More Python + Other Projects

1 min

Want to Code Another Python Game?

Materials

  • Computer with Repl.it access or VS Code + Python extension — 1 per student
  • Python cheat sheet (printed) — 1 per student

More robotics lessons

Ready to bring this lesson to your classroom?

Sign up to save this lesson, order supplies, and track student progress.