Rock Paper Scissors
Time to put it together: input, functions, conditionals, and loops in one small game against the computer. Get the basic version working first, then make it friendlier to play.
Overview
You'll build a text-based Rock, Paper, Scissors game with three functions and a main program, then improve it with repeated play and more forgiving input.
You've got it when…
- The computer makes a random choice and the player is prompted for theirs.
- The game correctly reports a win, loss, or tie.
- (Improved) The game repeats until the player quits, and accepts any capitalization or a single letter.
Collaboration & AI
Work: On your own. A neighbor can help you debug; the logic is yours.
AI — AIAS Level 1, No AI: Write the game logic yourself. What the levels mean.
Functions
Create these functions:
get_computer_choice()— accepts no arguments; returns one ofrock,paper, orscissorsat random.get_player_choice()— accepts no arguments; prompts the user to chooserock,paper, orscissorsand returns the chosen string. It rejects any illegal string and keeps prompting until a valid one is entered.determine_winner(player, computer)— accepts two strings, each expected to berock,paper, orscissors. It compares them and prints one of:You win!if the player wonI win!if the computer wonTie!if the choices match
Rules:
- Rock beats Scissors
- Scissors beat Paper
- Paper beats Rock
- Matching choices tie
Main Program
Write a main program that:
- Calls
get_player_choice()and stores the player's choice. - Calls
get_computer_choice()and stores the computer's choice. - Prints what the computer chose:
I chose ____. - Calls
determine_winner(), passing it the player's and computer's choices.
Improvements
Warning
Do not begin this section until the above sections are working properly.
Repeated Gameplay
- Enclose the main program in an infinite
whileloop so the game plays over and over. - Modify
get_player_choice()to allow a fourth option:quit. - Modify the main program to break out of the loop and quit if the player
chooses
quit.
Simplified User Input
- Modify
get_player_choice()to accept any capitalization by modifying the string the user types to all lowercase. Only lowercase strings may be returned. (rock,Rock,ROCK, andRoCkshould all returnrock.) -
Modify
get_player_choice()to accept a single letter for each choice (r,p,s,q). The function must still return the full word. The player may type the full word or just the letter.See the
startswithstring function for one way to do this.
Turn It In
- Your Python (
.py) file.
How It's Graded
This lab is worth up to 4 points. One score covers everything you turn in.
| Score | What it looks like |
|---|---|
| 4 — Excellent | The full game with both improvements: all nine choice combinations report the right winner (and ties tie), play repeats until quit, and get_player_choice() takes any capitalization or a single letter but only ever returns the lowercase word. You checked all nine combos, not just the three you like throwing. |
| 3 — Above Average | The improved game works, with a slip — one combo reported wrong, or one input form (say, RoCk) slipping past the cleanup. |
| 2 — Average | The base game plays one round correctly but the improvements are missing, or the winner logic is wrong in several combinations. |
| 1 — Below Average | The game can't finish a round, or the program doesn't run. |
| 0 — Failing | Nothing submitted, or no evidence of the game. |