Coding Challenge - Rock, Paper, Scissors
Objective:
Create a simple game of Rock, Paper, Scissors that you can play against the computer in your console (the terminal).
Problem Description:
- Player’s Choice: The player will choose one of three options: Rock, Paper, or Scissors.
- Computer’s Choice: The computer will randomly pick one of the three options.
- Determine the Winner: The game follows these rules:
- Rock beats Scissors
- Scissors beats Paper
- Paper beats Rock
- Display Results: Show the outcome of each round (e.g., Computer wins, Player wins, Tie).
- Multiple Rounds: Let the player play as many rounds as they want until they choose to stop.
Steps to Build the Game:
- Understand the Game Logic:
- Rules: Define the rules that determine who wins each round.
- Player Input: Use the
input()
function to ask the player for their choice. - Handle Invalid Inputs: Make sure the player can only choose Rock, Paper, or Scissors.
- Generate Computer’s Choice:
- Random Choice: Use Python’s
random
module to let the computer pick Rock, Paper, or Scissors randomly.
- Random Choice: Use Python’s
- Compare Choices and Determine the Winner:
- Create a Function: Write a function that takes the player’s choice and the computer’s choice, compares them, and decides who wins.
- Allow Multiple Rounds:
- Use a Loop: Use a loop (like
while True:
) to let the player keep playing until they choose to stop. - Ask to Continue: At the end of each round, ask if they want to play again. If they say no, end the game.
- Use a Loop: Use a loop (like
- Display Results:
- Show Choices and Results: After each round, print the player’s choice, the computer’s choice, and who won.
- End the Game:
- Exit Option: Give the player a way to quit the game by typing something like “quit” or “exit”.
- Keep Score: (Optional)
- Track Scores: You can keep track of how many rounds the player wins, loses, or ties, and display the scores at the end of the game.
This post is licensed under CC BY 4.0 by the author.