Creating a Rock Paper Scissors GAme (Python Lesson)
Learning Objectives:
- Understand and use sequence in an algorithm
- Understand and use iteration in an algorithm (FOR and WHILE loops)
- Understand and use selection in an algorithm (IF, Else and Else if)
- Understand and use data structures in an algorithm (for example, Lists, Tables or Arrays)
Curriculum Mapping:
KS2:
- Design, write and debug programs that accomplish specific goals; solve problems by breaking them into smaller parts. Select, use and combine a variety of software on a range of digital devices to design and create a range of programs.
- Use sequence, selection and repetition in programs; work with variables and various forms of input and output
- Use logical reasoning to explain how some simple algorithms work; detect and correct errors in algorithms and programs
KS3:
- Use two or more programming languages, at least one of which is textual, to solve a variety of computational problems.
STUDENT: COMPUTATIONAL THINKER:
- 5a: Students break problems into component parts, extract key information, and develop descriptive models to understand complex systems or facilitate problem-solving.
- 5c: Students break problems into component parts, extract key information, and develop descriptive models to understand complex systems or facilitate problem-solving.
- 5d: Students understand how automation works and use algorithmic thinking to develop a sequence of steps to create and test automated solutions.
EDUCATOR: COMPUTATIONAL THINKING COMPETENCIES:
- 4b: Design authentic learning activities that ask students to leverage a design process to solve problems with awareness of technical and human constraints and defend their design choices.
COMPUTER SCIENCE EDUCATORS:
- 2a: Plan and teach computer science lessons/units using effective and engaging practices and methodologies:
i. Select a variety of real-world computing problems and project-based methodologies that support active and authentic learning and provide opportunities for creative and innovative thinking and problem solving
ii. Demonstrate the use of a variety of collaborative groupings in lesson plans/units and assessments
iii. Design activities that require students to effectively describe computing artifacts and communicate results using multiple forms of media
iv. Develop lessons and methods that engage and empower learners from diverse cultural and linguistic backgrounds
v. Identify problematic concepts and constructs in computer science and appropriate strategies to address them
vi. Design and implement developmentally appropriate learning opportunities supporting the diverse needs of all learners
vii. Create and implement multiple forms of assessment and use resulting data to capture student learning, provide remediation and shape classroom instruction
CSTA K–12 CS Standards:
- 1B-AP-08: Compare and refine multiple algorithms for the same task and determine which is the most appropriate.
- 1B-AP-09: Create programs that use variables to store and modify data.
- 1B-AP-10: Create programs that include sequences, events, loops, and conditionals.
- 1B-AP-11: Decompose (break down) problems into smaller, manageable subproblems to facilitate the program development process.
- 1B-AP-13: Use an iterative process to plan the development of a program by including others' perspectives and considering user preferences.
- 1B-AP-15: Test and debug (identify and fix errors) a program or algorithm to ensure it runs as intended.
- 1B-AP-17: Describe choices made during program development using code comments, presentations, and demonstrations.
- 2-AP-11: Create clearly named variables that represent different data types and perform operations on their values
- 2-AP-12: Design and iteratively develop programs that combine control structures, including nested loops and compound conditionals.
- 2-AP-15: Seek and incorporate feedback from team members and users to refine a solution that meets user needs.
- 2-AP-16: Incorporate existing code, media, and libraries into original programs, and give attribution.
- 2-AP-17: Systematically test and refine programs using a range of test cases.
- 3A-AP-14: Use lists to simplify solutions, generalizing computational problems instead of repeatedly using simple variables.
- 3A-AP-15: Justify the selection of specific control structures when tradeoffs involve implementation, readability, and program performance, and explain the benefits and drawbacks of choices made.
AREA OF LEARNING AND EXPERIENCE: Science and Technology:
Computation is the foundation for our digital world.
Progression step 3
- I can use conditional statements to add control and decision-making to algorithms.
- I can identify repeating patterns and use loops to make my algorithms more concise.
- I can explain and debug algorithms.
Progression step 4
- I can decompose given problems and select appropriate constructs to express solutions in a variety of environments.
- I can select and use data structures that efficiently manage data in algorithms.
- I can plan and implement test strategies to identify errors in programs.
Progression step 5
- I can identify, define and decompose problems, choose appropriate constructs and express solutions in a variety of environments.
- I can use file-handling techniques to manipulate data in algorithms.
- I can test, evaluate and improve a solution in software.
How the game works
Rock-paper-scissors is a simple and popular hand game typically played between two people. The objective of the game is to outsmart your opponent by choosing a hand gesture that beats their choice. Here's how the game works:
- Players: The game is played between two players, often referred to as Player 1 and Player 2.
- Hand Gestures: Each player simultaneously makes one of three hand gestures representing rock, paper, or scissors:
- Rock: Form a closed fist with your hand.
- Paper: Extend your hand fully with fingers spread out.
- Scissors: Extend your hand and separate your index and middle finger to mimic a scissor shape.
- Winning Rules:
- Rock beats Scissors: Rock smashes scissors, so if a player chooses rock and the other chooses scissors, the player with rock wins.
- Paper beats Rock: Paper covers rock, so if a player chooses paper and the other chooses rock, the player with paper wins.
- Scissors beats Paper: Scissors cut paper, so if a player chooses scissors and the other chooses paper, the player with scissors wins.
- Ties: If both players choose the same gesture, it results in a tie, and the game is usually replayed.
In this lesson, students will learn to create a rock-paper-scissors game using Python. They will understand the basic concepts of conditionals, loops, and user input.
Starter:
Begin the lesson by explaining the rules of the rock-paper-scissors game to the students. Show a visual representation or use hand gestures to demonstrate how each item defeats or is defeated by another (rock crushes scissors, scissors cuts paper, paper covers rock).
Pair up students and have them play a few rounds of 'Rock Paper Scissors'.
Alternatively, students can play a game of Rock Paper Scissors against the computer: Rock Paper Scissors with AI (rockpaperscissors-ai.vercel.app)
- Start by explaining how to take user input in Python using the input() function.
- Instruct students to write a code snippet that takes user input for their choice of rock, paper, or scissors.
- Show them an example code snippet:
user_choice = input("Enter your choice (rock, paper, or scissors): ")
print("You chose: ", user_choice) |
5. Ask students to comment the code, using the hashtag (#), explaining what the code is doing.
- Introduce the concept of conditional statements (if, elif, else) to the students.
- Explain how to compare the user's choice with the computer's choice to determine the winner.
- Provide students with a code snippet as an example:
import random
user_choice = input("Enter your choice (rock, paper, or scissors): ") computer_choice = random.choice(["rock", "paper", "scissors"]) print("You chose:", user_choice) print("Computer chose:", computer_choice) if user_choice == computer_choice: print("It's a tie!") elif (user_choice == "rock" and computer_choice == "scissors") or \ (user_choice == "paper" and computer_choice == "rock") or \ (user_choice == "scissors" and computer_choice == "paper"): print("You win!") else: print("Computer wins!") |
- Explain the logic of the code and how the conditions are used to determine the winner.
- Ask students to run the code, play the game, and observe the output.
- Introduce the concept of loops to allow the players to play the game multiple times.
- Explain how a while loop can be used to repeatedly play the game until the player decides to stop.
- Provide students with a code snippet to add the play again functionality:
import random
while True: user_choice = input("Enter your choice (rock, paper, or scissors): ") computer_choice = random.choice(["rock", "paper", "scissors"]) print("You chose:", user_choice) print("Computer chose:", computer_choice) if user_choice == computer_choice: print("It's a tie!") elif (user_choice == "rock" and computer_choice == "scissors") or \ (user_choice == "paper" and computer_choice == "rock") or \ (user_choice == "scissors" and computer_choice == "paper"): print("You win!") else: print("Computer wins!") play_again = input("Do you want to play again? (yes/no): ") if play_again != 'yes': break |

rock_paper_scissors.zip |
Extension:
Ask the students to test what happens if they answer 'Yes' or 'YES' when asked if they want to play the game again.
1. Challenge the students to modify their code to fix the error.
Hint:
if play_again.lower() != 'yes':
break |
Additional challenge
Challenge students to create a game of Rock Paper Scissors Lizard Spock.
Unless otherwise specified, everything in this repository is covered by the following licence:
Based on the Shakespearean Insulter: http://www.pangloss.com/seidel/Shaker/