Title: Rock, Paper, Scissors Game with Input Validation and Score Tracking
Original Exercise:
Rock, Paper, Scissors Modification Programming Exercise 11 in Chapter 6 asked you to design a program that plays the Rock, Paper, Scissors game. In the program, the user enters one of the three strings—"rock", "paper", or "scissors"—at the keyboard. Add input validation (with a case-insensitive comparison) to make sure the user enters one of those strings only.
Description from Chapter 6:
Rock, Paper, Scissors Game Design a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows:
A. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. (Don’t display the computer’s choice yet.)
B. The user enters his or her choice of "rock," "paper," or "scissors" at the keyboard.
C. The computer’s choice is displayed.
D. The program should display a message indicating whether the user or the computer was the winner. A winner is selected according to the following rules: If one player chooses rock and the other player chooses scissors, then rock wins. (The rock smashes the scissors.) If one player chooses scissors and the other player chooses paper, then scissors wins. (Scissors cut paper.) If one player chooses paper and the other player chooses rock, then paper wins. (Paper wraps rock.) If both players make the same choice, the game must be played again to determine the winner.
Modifications:
1) Use input validation to allow the following: Allow the user to input "r", "p", "s" or the full strings "Rock", "Paper", "Scissors".
2) Allow the user to input upper or lowercase.
3) Allow the player to input a "q" or "Q" or "quit" or "QUIT" for their turn if they want to quit the game.
4) Allow the player to quit at any time, do not force a tiebreaker. Try the following: input = input.lower() if(user_input[0].lower() == 'q').
5) Refer to the following code to help generate a random computer player action: import random pc_choice_list = ["rock", "paper", "scissors"] pc_choice = random.choice(pc_choice_list).
6) Keep a running total of the score for both the player and computer. Display the final scores in human-readable format at the end.
7) Example outputs: Rock beats Scissors, Paper beats Rock, Scissors beats Paper, Tie, Game Over. Let's Play Rock, Paper, Scissors. Input your choice: