Question

In: Computer Science

Modified from Chapter 07 Programming Exercise 5 Original Exercise: Rock, Paper, Scissors Modification Programming Exercise 11...

Modified from Chapter 07 Programming Exercise 5

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.

Modifications:

  • Allow the user to input "r", "p", "s" or the full strings "Rock", "Paper", "Scissors"
    • Allow the user to input upper or lowercase
    • try the following:
      • input = input.lower()
  • 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)
  • Allow the player to input a "q" for their turn if they want to quit the game
  • Use loops not only to validate the input but also to keep the game running as long as the player does not input a "q" on their turn
  • Example outputs
    • Rock beats Scissors
    • Paper beats Rock
    • Scissors beats Paper
    • Tie
    • Game Over
    • Let's Play Rock, Paper, Scissors
      Input your choice: r,p, or s

Turn IN:

Raptor flowchart file (or alternative flowchart screenshot)
        If you are on Windows please try using the built-in "Snip & Sketch" program to take a perfectly sized screenshot.
Thonny Python file (or Python file is written in any IDE/program)
        Turn in the actual Python code file "file_name.py"

Solutions

Expert Solution

import random #import random for pc_choice

pc_choice_list = ["rock", "paper", "scissors"] #choices with computer

check = False #variable to check whether q has been pressed or not

while check == False:
    # loop will run until q is pressed
    pc_choice = random.choice(pc_choice_list) # randomly pc selecting its choice from the availabe options
    
    print("Let's Play Rock, Paper, Scissors")
    
    player = input("Input your choice: r,p, or s:")  #taking input
    
    player=player.lower() #making the input string lowercase 
    
    if player=="r":
        player="rock"
        # if r is entered by player then making it rock to compare it easily with pc_choice
    if player=="p":
        player="paper"
        # if p is entered by player then making it paper to compare it easily with pc_choice
    if player=="s":
        player="scissors"
        # if s is entered by player then making it scissors to compare it easily with pc_choice
    if player == pc_choice:
        print("Tie!")
        
    elif player == "rock":
        if pc_choice == "Paper":
            print("Lose!! paper beats rock")
        else:
            print("You win!! rock beats scissors")
            
    elif player == "paper":
        if pc_choice == "scissors":
            print("Lose!! Scissors beats Paper")
        else:
            print("You win!! Paper beats Rock")
            
    elif player == "scissors":
        if pc_choice == "rock":
            print("Lose!! Rock beats Scissors")
        else:
            print("You win!! Scissors beats Paper")
            
    elif player=="q":
        print("Game Over")
        check=True
        #if player enters q then check is true and condition in while loop becomes false so loop breaks
    else:
        print("That's not a valid play. Check your spelling!")
        #if not a valid string.
        
        

If you need any files or have any problem comment below.

Please upvote.

Cheers!!


Related Solutions

Repl.it Python Ch 07 #5: Rock, Paper, Scissors Modification Programming Exercise 11 in Chapter 6 asked...
Repl.it Python Ch 07 #5: 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. I demonstrated the implementation of the program here: https://repl.it/@profeldridge/week06assignment06part2of2#main.py Using the repl.it link above,...
Develop a C++ program that plays out a round of Rock, Paper, Scissors using Functional Programming...
Develop a C++ program that plays out a round of Rock, Paper, Scissors using Functional Programming 1) Develop a function that prompts the user to enter their choice (1=Rock 2=Paper 3=Scissors) Return either a 1, 2, or 3 depending on the value the user has entered Do not continue the program until the user has entered a valid choice of 1, 2, 3 2) Develop a function that generates the computer player's choice Return either a 1, 2, or 3...
write a python script for rock scissors paper game
write a python script for rock scissors paper game
In the game Rock Paper Scissors, two players simultaneously choose one of three options: rock, paper,...
In the game Rock Paper Scissors, two players simultaneously choose one of three options: rock, paper, or scissors. If both players choose the same option, then the result is a tie. However, if they choose differently, the winner is determined as follows: • Rock beats scissors, because a rock can break a pair of scissors. • Scissors beats paper, because scissors can cut paper. • Paper beats rock, because a piece of paper can cover a rock. Create a game...
In the game Rock Paper Scissors, two players simultaneously choose one of three options: rock, paper,...
In the game Rock Paper Scissors, two players simultaneously choose one of three options: rock, paper, or scissors. If both players choose the same option, then the result is a tie. However, if they choose differently, the winner is determined as follows: • Rock beats scissors, because a rock can break a pair of scissors. • Scissors beats paper, because scissors can cut paper. • Paper beats rock, because a piece of paper can cover a rock. Create a game...
Chapter 8 Programming exercise 6 "Days of each month" Original Exercise: Design a program that displays...
Chapter 8 Programming exercise 6 "Days of each month" Original Exercise: Design a program that displays the number of days in each month. The program’s output should be similar to this: January has 31 days. February has 28 days. March has 31 days. April has 30 days. May has 31 days. June has 30 days. July has 31 days. August has 31 days. September has 30 days. October has 31 days. November has 30 days. December has 31 days. The...
Write a Java class that determines the winner of a rock, paper scissors game. Assume the...
Write a Java class that determines the winner of a rock, paper scissors game. Assume the input from the user is always valid (so no need to check), that is it contains either one of `R`, `P`, or `S` as a single character, or has matching parenthesis, like, `(S&P)` or `((R&P)&S)`, and the `&` character. So for example, the user inputs `(P&R)` and the program will output `P` since paper beats rock. Or if the user inputs `((S&R)&(S&S))` the output...
Solve the scissors, paper, rock game. This game is well known in many parts of the...
Solve the scissors, paper, rock game. This game is well known in many parts of the world. Two players simultaneously present a hand in one of three positions: an open hand (paper), a closed fist (rock), or two open fingers (scissors). The payoff is 1 unit according to the rule “Paper covers rock, rock breaks scissors, and scissors cut paper.” If both players present the same form, the payoff is 0. Set up the payoff matrix for the game and...
One file java program that will simulate a game of Rock, Paper, Scissors. One of the...
One file java program that will simulate a game of Rock, Paper, Scissors. One of the two players will be the computer. The program will start by asking how many winning rounds are needed to win the game. Each round will consist of you asking the user to pick between rock, paper, and scissors. Internally you will get the computers choice by using a random number generator. Rock beats Scissors, Paper beats Rock, and Scissors beats Paper. You will report...
Please write a scheme code for the rock paper scissors game between a player and the...
Please write a scheme code for the rock paper scissors game between a player and the computer (AI). In scheme programming language please.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT