1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
lana66690 [7]
4 years ago
13

Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follo

ws: 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. (Do not display the computer's choice yet) The user enters his or her choice of "rock", "paper, or "scissors" at the keyboard. The computer's choice is displayed. A winner is selected according to the following rules: If one player chooses rock and the other player chooses scissors, then rock wins. (Rock smashes scissors.) If one player chooses scissors and the other player chooses paper, then scissors wins. (Scissors cuts paper.) If one player chooses paper and the other play 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.

Computers and Technology
1 answer:
aleksley [76]4 years ago
7 0

Answer:

Here is the Python program for the game rock, paper, scissors.

import random

def computerChoice():  #function for the computers choice

   randomNumber = random.randint(1,3)  

# generates random no in the range of 1 through 3

   if randomNumber == 1:  #if that random number is equal to 1

       return 'rock'  #computer has chosen rock

   elif randomNumber == 2:  #if random number is equal to 2

       return 'paper' #computer has chosen paper

   else:

       return 'scissors'  #computer has chosen scissors

def validChoice(choice):  #function which checks if user enters right choice

   return choice == 'rock' or choice == 'paper' or choice == 'scissors'

    #the right choice is one of the following rock paper or scissor

def invalidChoice(choice):  #function to check if user entered invalid choice

#loop continues until the user enter the correct given choice

   while choice != 'rock' and choice != 'paper' and choice != 'scissors':

         print('That is not a valid choice.')  

         choice = input('\nEnter rock, paper, or scissors: ')

   return choice

def winner(player, computer): # function to decide who wins the game

   if player == 'rock' and computer == 'scissors':  

#if player chooses rock and computer has chosen scissors

       print("rock smashes scissors")  #display this message

       return True  #function returns true

        #if player chooses scissors and computer has chosen paper

   elif player == 'scissors' and computer == 'paper':

       print("scissors cuts paper")

       return True

     #if player chooses paper and computer has chosen rock

   elif player == 'paper' and computer == 'rock':

       print("paper wraps rock")

       return True          

   else:

       return False  

compChoice = computerChoice()  #stores the choice made by computer

playerChoice = input('Choose from rock, paper, or scissors: ')

#stores what player inputs as his choice

if not validChoice(playerChoice):  #if the choice is not valid

   playerChoice = invalidChoice(playerChoice)  

#calls invalid function to take valid input choice from user

while playerChoice == compChoice:  

#loop continues to execute until the winner is decided

   print('Computer\'s choice:', compChoice)

#if there is a tie then the game is played again to determine the winner

   print('Its a tie!  Choose again.')      

   compChoice = computerChoice()

   playerChoice = input('\nEnter rock, paper, or scissors: ')

   if not validChoice(playerChoice):

       playerChoice = invalidChoice(playerChoice)

#if player wins congratulation message is displayed

print('Computer\'s choice:', compChoice)

if winner(playerChoice, compChoice):

   print('Congratulations! You win!')

else:  #if player loses from computer

   print('You lose! Computer wins!')  

Explanation:

This program has following methods:

computerChoice() This function generates random number in the range of 1 through 3 to take choice from the computer and it uses random.randint() to generate random number from the given range. If the random number is 1 then the computer has chosen rock and if random number is 2 then the computer has chosen paper otherwise scissors.

validChoice() function sets the choice variable to rock, paper and scissors which means user should enter one of these available choices.

invalidChoice() function checks if user entered invalid choice. Invalid choice is anything entered other than rock, paper, scissors. While loop continues to execute and keeps asking to enter a choice until the user enter the correct given choice. It displays That is not a valid choice if user enters an invalid choice.

winner() function determines the winner between computer and player by comparing the choices entered by player and computer. For example if the player enters rock and computer has chosen scissors then this message is displayed rock smashes scissors and function returns true. This means player wins.

Lastly the main program prompts user to enter a choice and stores computer's choice too and compares both the choices to determine the winner accordingly. If there is tie then the game is started again to determine the winner.

The output is attached.

You might be interested in
How do I fix this stylesheet?
aalyn [17]

Answer:

i dont know

Explanation:

i m really sorry :(

6 0
3 years ago
The traditional role of a manager is that of a(n):__________ a. encoder. b. sensegiver. c. communication champion. d. informatio
GREYUIT [131]

The traditional role of a manager is that of a(n):<u> information processor.</u>

<u></u>

<h3>What is called as information processing?</h3>

information processing , the acquisition, recording, organization, retrieval, display, and dissemination of information. In recent years, the term has often been applied to computer-based operations specifically. information processing.

<h3>What is information processing in computer?</h3>

Information processing refers to the manipulation of digitized information by computers and other digital electronic equipment, known collectively as information technology (IT). Information processing systems include business software, operating systems, computers, networks and mainframes.

To learn more about Information processing , refer

brainly.com/question/6392847

#SPJ4

7 0
2 years ago
Write a code segment that prints the food item associated with selection. For example, if selection is 3, the code segment shoul
Ganezh [65]

<em>Missing Part:</em>

<em>Assume that the following variables have been properly declared and initialized: an int variable named selection, where 1 represents "beef", 2 represents "chicken", 3 represents "pasta", and all other values represent "fish"</em>

Answer:

if selection == 1:

    print("beef")

elif selection == 2:

    print("chicken")

elif selection ==3:

    print("pasta")

else:

    print("fish")

Explanation:

I've completer the question and the questin will be answered in python.

   

This checks if selection is 1. If yes, it prints the beef

<em>if selection == 1:</em>

<em>     print("beef")</em>

This checks if selection is 2. If yes, it prints the chicken

<em>elif selection == 2:</em>

<em>     print("chicken")</em>

This checks if selection is 3. If yes, it prints the pasta

elif selection ==3:

    print("pasta")

Any other input is considered java/

else:

    print("fish")

4 0
3 years ago
Prompt the user to input five pairs of numbers: A player's jersey number (0 - 99) and the player's rating (1 - 9). Store the jer
tiny-mole [99]

Answer:

  1. import java.util.Scanner;
  2. public class Main {
  3.    public static void main (String [] args) {
  4.        int jersey_num [] = new int[5];
  5.        int rating [] = new int[5];
  6.        Scanner inStream = new Scanner(System.in);
  7.        for(int i=0; i < 5; i++){
  8.            System.out.print("Enter player " + (i+1) + "'s jersey number:");
  9.            jersey_num[i] = inStream.nextInt();
  10.            System.out.print("Enter player " + (i+1) + "'s rating:");
  11.            rating[i] = inStream.nextInt();
  12.        }
  13.        System.out.println("ROSTER");
  14.        for(int j=0; j < 5; j++){
  15.            System.out.println("Player " + (j+1) + "-- Jersey number: " + jersey_num[j] + ", Rating: " + rating[j]);
  16.        }
  17.    }
  18. }

Explanation:

The solution code is written in Java. Firstly create two array, jersey_num and rating, with int type. This is to hold the five pairs of numbers input by user (Line 6 -7).

Next, create a for loop that run for 5 iterations and in each iteration prompt user to input jersey number and rating (Line 11 -17). The input number and rating will be set to the array, jersey_num and rating, respectively.

Next, print the title "Roster" (Line 19).

Create another for loop to display the five input pair of values (Line 21 - 23).

3 0
3 years ago
3 Which of the following statements are true about how technology has changed work? Select 3 options. With the spread of technol
madam [21]

Answer:

In a gig economy, workers are only hired when they are needed for as long as they are needed.

Businesses can be more profitable by using communication technology to reduce the costs of travel.  

Through the use of the Internet and collaboration tools, more workers are able to perform their jobs remotely.

Explanation:

7 0
3 years ago
Other questions:
  • Where can you access all the formatting options for worksheet cells?
    5·1 answer
  • Which trait depicts honesty?
    10·1 answer
  • Write a Java class called getName that prompts a user for their name and then displays "Hello, [name here]!" The flow should loo
    14·1 answer
  • #Write a function called 'string_type' which accepts one #string argument and determines what type of string it is. # # - If the
    8·1 answer
  • Which scenario describes unethical lab behavior?
    9·1 answer
  • PowerPoint is a visual aid for many speakers. Discuss some points to remember when adding text to a PowerPoint presentation. How
    8·1 answer
  • Fiber optic cables transfer data at the speed of light, so they have the __________ latency. This results in the ________ connec
    13·1 answer
  • Ethan is a project manager who is responsible for overseeing overall budget and schedule. Which tool is he is MOST likely to use
    7·1 answer
  • Name 3 things that you use daily that are considered computers?
    6·1 answer
  • Your friend Cameron’s little sister is visually impaired. Cameron is worried that his sister will not be able to use technology
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!