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
What is the difference between grid computing, beowulf clusters, and blade computing?
Licemer1 [7]

Answer:

 The grid computing is the type of processor architecture which basically combine all the resources of the computer system from the various type of domain for reaching the main goal. In the the grid computing all the computer perform all the task together in the network.

The main difference between the beowulf cluster and the grid computing is that the cluster is the homogeneous on the other hand the grid is heterogeneous. The grid computing can run the different types of operating system and cluster computers include similar type of operating system and hardware.

The beowulf cluster is the type of the computer cluster that are easily identical in the local area network. It basically allow the programs to be installed in the system.

Blade computing is the type of server blade in the cloud computing technology that basically refers to the high density server in the networking system. It is the compact device which is used to manage the data in the computer system.

6 0
3 years ago
Data refer to
Yanka [14]
D. Large sets of information that can be analyzed for patterns and trends
3 0
3 years ago
Need help with understanding Project Reactor<br><br> https://projectreactor.io/
ddd [48]

Answer:

IT IS LIKE A ONILE AND THE PERFECT

Explanation:

THIS IS YOUR ANSWER

I HAVE EXPLAINED YOU

8 0
3 years ago
Write a function that takes an integer and reverses the digits. The function returns the reversed number to main. Here is the pr
laila [671]

Answer:

The prototype part missing has been assumed to be:

int reverseNum (int num);

Code:

#include <iostream>

using namespace std;

int reverseNum(int num);

int main()

{

int num=0,result=0;

cout<<"Enter the number:";

cin>>num;

result=reverseNum(num);

cout<<"The reversed number :"<<result<<endl;

return 0;

}

int reverseNum(int num)

{

int temp=0,digit=0;

for(num;num>0;num=num/10)

{

digit=num%10;

temp=temp*10+digit;

}

return temp;

}

Explanation:

5 0
3 years ago
A group of Automation Anywhere Enterprise users are required to automate bots for a customer change requirement. The users find
stich3 [128]

There are a number of tools that have emerged since Automation was born. One such tool is the Automation Anywhere. It is a good example of an RPA tool that is used to automate various tasks and upload task bots. Automation Anywhere is made up of three main components. These components include Bot Creators, Bot Runners, and Control Room.

Further explanation

To answer the question, it is most likely that these users have a Community edition which does not allow them to upload bots to the control room. It is also most likely that the users are running a developer license and not a runner (Enterprise) license. Whether or not this is the case, the administrator needs to assign them an administrator role and not a developer one which I assume they are using

Community edition helps users interact with the most basic features of the tool before they are comfortable enough to upgrade to the Enterprise version. These users are able to automate bots for customers only if they have the Administrator role option. The Administration option is found on the Enterprise edition only and not the community edition.

Learn more about

brainly.com/question/11317405

brainly.com/question/11317405

#LearnWithBrainly

6 0
3 years ago
Other questions:
  • How do I make my own extension for chrome?
    7·1 answer
  • Barat explains that if you have a cell that is the sales price of a given product, the value of which will change to produce the
    9·1 answer
  • Green Field county stadium is planning to conduct a cricket match between two teams A and B. A large crowd is expected in the st
    6·1 answer
  • Which of the following statements is true?
    14·1 answer
  • What is VLSI stand for​
    14·1 answer
  • Join Viber Creations on Viber https://invite.viber.com/?g2=AQAboWGw5hKZN009gOjCULc4cbWKWg42%2BIFmJoPC93MPlt9kstcpJyU6yagPh050 |
    6·1 answer
  • Logical are functions used when looking for an entry or value in the spreadsheet. what is it?
    13·1 answer
  • If there is a combination of two or more attributes which is being used as the primary key then we call it as
    12·1 answer
  • an existing technology that would allow users to transfer images from the camera to the computer without connecting them
    8·1 answer
  • __________ is a computer tool for evaluating the risk of exposure to wildfires.
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!