Here is the python code to the given question.
Two sample outputs are added at the end.
Code:
import random
def checkWin(userChoice,computerChoice):
"""Checks whether the user has won the game.
Parameters:
userChoice(int) : choice entered by the user.
computerChoice(int) : choice chosen by computer.
Returns:
Boolean : True if user wins and False if computer wins.
"""
if (userChoice==1 and computerChoice==3) or (userChoice==2 and computerChoice==1) or(userChoice==3 and computerChoice==2):
return True
else:
return False
def getRandomNumber():
"""Generates a random number from 1-3.
Parameters:
None
Returns:
int : random number from 1-3
"""
return random.randint(1,3)
def getName(choice):
"""Gets the text representation of the choice
Parameters:
choice(int) : choice entered by user or chosen by computer
Returns:
String : text representation of the choice
"""
if choice==1:
return "rock"
elif choice==2:
return "paper"
elif choice==3:
return "scissors"
def main():
"""Simulates Rock,Paper,Scissors game."""
computerChoice=getRandomNumber() #get computer generated choice
while True:
userChoice=int(input("Enter 1 for rock, 2 for paper , 3 for scissors: ")) #get user choice and convert it into int
print("Computer chose",getName(computerChoice)) #print computer choice
print("You chose",getName(userChoice)) #print user's choice
if userChoice==computerChoice: #check if user choice equals computer choice
print("You made the same choice as the computer. Starting over")
else:
if checkWin(userChoice,computerChoice): #check if user has won the game
print("You win the game")
else:
print("Computer wins the game")
break #exit from while loop
if __name__=="__main__":
main() #calls main
Sample Output-1:
Sample Output-2:
In python language Write a program that lets the user play the game of Rock, Paper,...
C++ Part 2: Rock Paper Scissors Game Write a program that lets the user play this game against the computer. The program should work as follows: When the program begins, a random number between 1 and 3 is generated. If the number is 1, the computer has chosen rock. If the number is 2, the computer has chosen paper. If the number is 3, the computer has chosen scissors. Don't display the computer's choice yet. Use a menu to display...
Write a Python program (using python 3.7.2) that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. 1. 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...
IN JAVA. Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. 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....
(Java) Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. 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. The...
In JAVA Chapter 5Assignment(Rock, Paper, Scissors)–20pointsYour goal is towrite a program that lets the user play the game of Rock, Paper, Scissors against the computer.Your program should have the following: •Make the name of the project RockPaperScissors•Write a method that generates a random number in the range of 1 through 3. The randomly generated number will determine if the computer chooses rock, paper, or scissors. If the number is 1, then the computer has chosen rock. If the number is...
It's writing a simple rock paper scissors game strictly following the instructions. INSTRUCTIONS: If the user selects 'p': 1. First the program should call a function named getComputerChoice to get the computer's choice in the game. The getComputerChoice function should generate a random number between 1 and 3. If the random number is 1 the computer has chosen Rock, if the random number is 2 the user has chosen Paper, and if the random number is 3 the computer has...
You are asked to implement scissors-rock-paper game where the players are a computer and a user. The player that wins 3 hands successively is the winner of the game. Your program should prompt the user with a message at the beginning of each hand to enter one of scissors, rock or paper. If the user's entry is not valid, i.e. entry is neither scissors, rock, nor paper, your program throws a message to the user to enter a valid entry...
In this problem, you’ll play a simple rock, paper, scissors game. First, you’ll ask the user to pick rock, paper, or scissors. Then, you’ll have the computer randomly choose one of the options. After that, print out the winner! You should keep playing the game until the user hits enter. Note: You’ll need to implement a method called String getWinner(String user, String computer). Luckily, you just wrote that in an earlier program! Here is a sample run of the program....
Write a C# program that allows one user to play Rock-Paper-Scissors with computer. The user will pick a move (Rock Paper Scissors) from 3 radio buttons and click the play button to play the game. The application will use random number generator to pick a move for the computer. Then, the application display the computer's move and also display whether you won or lost the game, or the game is tie if both moves are the same. The application must...
Write a Python program (rock_paper_scissors.py) that allows two players play the game rock paper scissors. Remember the rules: 1. Rock beats scissors 2. Scissors beats paper 3. Paper beats rock The program should ask the users for their names, then ask them for their picks (rock, paper or scissors). After that, the program should print the winner's name. Note, the players may pick the same thing, in this case the program should say it's tie. when the user input an...