Level 1
0 / 100 XP

Assignment: Rock, paper, scissors

Great job learning about loops and functions, students! Now it's time to put your new knowledge to the test with a fun assignment.

For this assignment, you will create a program that plays the classic game Rock Paper Scissors. Here are the rules of the game:

  • The game is played by two players, who each choose one of three options: rock, paper, or scissors.
  • If both players choose the same option, the game is a tie.
  • Otherwise, rock beats scissors (because rock smashes scissors), scissors beats paper (because scissors cut paper), and paper beats rock (because paper covers rock).

Your program should ask the user for their choice and then randomly choose a choice for the computer. It should then determine the winner of the round and keep track of the score. The game should continue until the user decides to quit.

Example output

SQL
Chose an option below: 0: Rock 1: Paper 2: Scissors Please select a valid option above: 1 Player's choice: Paper Computer's choice: Paper It's a tie!

Try the game here!

Tips

Here are some tips to help you get started:

Step 1

Import the Python random module at the top

Code

import random

Step 2

Create variable named choices that is an array of dictionaries that contain two values:

  • name (Name of the choice like, rock, paper or scissors)
  • beats (The name of the choice that it beats, for example, name=rock would contain beats=scissors)

Code

Text
# Define the choices and the index of the other choice it will beat choices = [ { 'name': 'Rock', 'beats': 'Scissors' }, { 'name': 'Paper', 'beats': 'Rock' }, { 'name': 'Scissors', 'beats': 'Paper' }, ]

Step 3

  • Write a function called get_computer_choice that returns a random item from the choices dictionaries…