Rock Paper Scissors Challenges
After completing the code-along, attempt the challenges below.
Optional Practice: Bug Fixes
View these buggy Repl projects and try to fix them. Test the program and make sure that all outcomes are reachable.
1. Nicer Printing
While the program should be functional after the code-along, it does not have the best user experience. Update the code to make it a little easier to read for the user.
- Add an empty
print
statement under the "Welcome" message to make a new line under it - Add another empty
print
statement above the finalinput
in thewhile
block - Add another empty
print
statement at the bottom of thewhile
block - Add
print
statements above and below thebattle
output, adding a "box" using dashes
Run the program, and make sure it is a little more usable!
BONUS: ASCII Art
ASCII art is a graphic design technique that creates images from text characters. Utilize some ASCII art to make the program more exciting!
In Python, it is possible to create multiline strings, which can make ASCII art much easier. Instead of using a single double quote ( "
) to start and end a string, use three double quotes ( """
).
For example, this code:
value = """this is a
multiline
string"""
print(value)
will print this:
this is a
multiline
string
An example of art for Rock Paper Scissors can be found here: https://gist.github.com/wynand1004/b5c521ea8392e9c6bfe101b025c39abe
2. Handling Invalid Input
At the moment, the program works if the user enters "R", "P", or "S". However, if the player enters anything else, no message is displayed. Make some updates so that this is properly handled.
- In the
battle
function, find the bottom of the block - At the same level as the first
if
, add anelse:
clause - In the
else
block, print a message saying "Invalid Selection"
Run the program, and verify that invalid input sees a proper response!
BONUS: Boxify Valid Battle
As it is, the "Invalid Selection" will display in the same "box" as the battle statement. Update the code so that the "box" dashes only appear for a legitimate battle.
3. Tracking Score
This challenge is a little more difficult. One nice feature for the program would be the ability to track a player's wins across multiple games.
- Find the
battle
function definition - Find each
print
statement where the player wins - Under each of those statements, with the same indentation level, add
return True
- This
True
indicates that the player won the battle
- This
- For each other
print
statement, addreturn False
directly beneath - Above the
while
loop, create a new variable namedscore
- Set the value of the
score
variable to0
- Within the
while
loop, find thebattle
function call - Set the result of the
battle
call to a new variable:won
- Under the
battle
call, create anif
statement - Make the
if
statement check ifwon
isTrue
- In the block of the
if
statement, increment the value ofscore
by1
- Under the
if
statement (outside the indented block), create aprint
- Make the
print
statement print out thescore
variableprint("Score: " + str(score))
Run the program again, and verify that the score goes up with every victory!
4. More Moves
This challenge may be quite difficult. One variation of the game adds two additional move options: Spock and Lizard. This version was invented by Sam Kass and Karen Bryla, and later popularized by the CBS sitcom The Big Bang Theory.
The outcomes are as follows:
It adds this additional logic:
- Rock vs. Spock - L
- Rock vs. Lizard - W
- Paper vs. Spock - W
- Paper vs. Lizard - L
- Scissors vs. Spock - L
- Scissors vs. Lizard - W
Update the program so that it can handle these additional cases.
5. Hangman, Tic Tac Toe, or Something Else
Create a completely different console game using the same programming concepts from the Rock Paper Scissors game. Add some ASCII Art to make it fun.