Assignment: Rock, paper, scissors
Server Academy Members Only
Sorry, this lesson is only available to Server Academy members. Create a free account now to get instant access to this and more free courses. Click the Sign Up Free button below to get access to our free courses now, or sign in if you have an account.
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:
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
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
Step 2
Create variable named choices that is an array of dictionaries that contain two values:
Code
Step 3
Code
Step 4
Create a menu that will list all the possible selections and their index (rock, paper, scissors). You can use this code to have access to the index value and choice.
Code
Step 5
Prompt the user to select and index shown above and then assign the computer's choice to a variable using the get_computer_choice function
Hint
Code
Step 6
Output the player's and computer's choice
Code
Step 6
Determine the winner by using the choice.get('name') and choice.get('beats')
Code
Solution
Here is the full code solution if you get stuck or if you have completed the challenge and want to see how I solved wrote the program.
Before you view the code!
But now that I have guilted you (lol), you can view the full code solution below
Full code solution
Server Academy Members Only
Want to access this lesson? Just sign up for a free Server Academy account and you'll be on your way. Already have an account? Click the Sign Up Free button to get started..
Saving Progress...
Python 3 for Beginners
Installing Python on Windows • 1hr 17min
0 / 4 lessons complete
Section Overview
Free Preview Lesson
Text | 1 min
Downloading and Installing Python on Windows
Free Preview Lesson
Text | 8 min
Installing and configuring VS Code for Python
Free Preview Lesson
Text | 8 min
Lab: Installing Python
Devops Lab | 60
Python Basics • 28min
0 / 7 lessons complete
Section Overview
Text | 2 min
Executing Python Code
Free Preview Lesson
Text | 3 min
Python 3 Syntax
Free Preview Lesson
Text | 5 min
Help! Python Keywords
Free Preview Lesson
Text | 4 min
Printing to the console!
Text | 5 min
Python Operators
Text | 4 min
Section Review
Quiz | 5 min
Python Variables • 41min
0 / 8 lessons complete
Section Overview
Text | 4 min
Casting
Text | 4 min
Strings
Text | 5 min
Booleans
Text | 8 min
User Input
Text | 2 min
Numbers
Text | 7 min
NoneType
Free Preview Lesson
Text | 5 min
Assignment: Write a Mad Libs Script
Text | 6 min
Even more Python Variables! • 41min
0 / 6 lessons complete
Python Lists
Text | 8 min
Python Tuples
Text | 7 min
Python Sets
Text | 7 min
Frozensets
Text | 6 min
Dictionaries
Text | 8 min
Iterator and Iterable
Text | 5 min
Conditional Statements • 15min
0 / 3 lessons complete
Writing Functions • 30min
0 / 5 lessons complete
Python Loops • 23min
0 / 5 lessons complete
Section Overview
Text | 2 min
For In Loops
Text | 5 min
While Loops
Text | 5 min
Nested Loops
Text | 3 min
Python Loops Challenge!
Text | 8 min
Python PIP and Modules • 18min
0 / 4 lessons complete
Section Overview
Text | 3 min
Installing Python PIP
Text | 4 min
Installing Modules with PIP
Text | 5 min
Importing Modules
Text | 6 min
RegEx • 26min
0 / 4 lessons complete
Section Overview
Text | 4 min
Regex 101
Text | 10 min
Importing Regex and manipulating strings
Text | 7 min
Regex Challenge!
Text | 5 min
Working with APIs • 12min
0 / 3 lessons complete
Making HTTP Requests
Text | 3 min
Working with JSON
Text | 5 min
Get your weather with the OpenWeatherMap
Text | 4 min
Course Conclusion • 2min
0 / 1 lessons complete
The full code kind of work. The option to pick pops up but once you choose the option you get hit with an error message talking about line 34
Hi Idris Williams
You are right. The error shows when running the code. It seems the error is with player_choice_string that needs to be converted to integer form string.
We went ahead and check the code and added the need code to fix it.
Ricardo