Text Based Games
1 Rock, Paper, Scissors
- Click here for the 2015 version for this lesson
Learn It
- We are going to recreate the game of rock paper scissors in python.
- First let us remind ourselves how the game works.
- There are 3 possible choices that either player can make:
- Rock, paper, scissors
- Rock beats scissors
- Paper beats rock
- Scissors beat paper
- There are 3 possible choices that either player can make:
Code It
- The human will pick their own choice and the computer will pick one at random.
- For the computer to choice at random the python random module must be imported, this is done in the very first line of your code.
- The possible choices are going to be stored in List – a python data type for holding multiple items.
- The
random.randint
function will be used to create a random number between 0 and 2.
- Why 0 to 2?
- The human will need to be asked for an input to capture their choice.
Learn It
- There are 9 possible outcomes of the game
Please create a table, like the example below, of all possible outcomes.
- Now that would be many lines of code but do we need to program all the possible cases?
- If the computer and human choose the same, it’s a draw
- If the outcome this 1 of the 3 computer win cases, the computer wins
- Else the human must have won.
Code It
- Python representation of the flow chart above
Badge It - Silver
- Silver: Upload a screen shot of your complete outcomes table
- Gold: Upload a screen shot of your code with comments
- Platinum: To improve our application we will give the user the option of playing again. The code below show you how to structure a while loop to keep the application running.