Question: Lab 2 Assignment: Rock, Paper, Scissors Write a program that plays a game of rock, paper, scissors with the computer. The rules of this game
Lab 2 Assignment: Rock, Paper, Scissors
Write a program that plays a game of rock, paper, scissors with the computer. The rules of this game involve each opponent to throw their hand forward with one of the three symbols that represent rock, paper, scissors, respectively. If a tie happens, the opponents choose again. This keeps happening until each opponents hands are different. The possible outcomes are as followed:
Rock beats Scissors
Scissors beats Paper
Paper beats Rock
Your program should allow the user to complete multiple rounds of this game if the user wishes to continue. Your program should work as followed:
1.Start the first round.
2.Ask the user for their choice of Rock, Paper, Scissors
3.Randomly choose Rock, Paper, Scissors for the computer.
4.Determine who won.
a. If there is a tie, repeat steps 2 4.
b. If there is a winner, determine who the winner is.
5.Output the winner of the round.6.Ask the user if he/she wants to play again.
a. If yes, repeat steps 1 6.
b. If no, exit program.
Functions Required
This program MUST be divided into the following functions. Each function must be called(other than main...) in the program to achieve assignment requirements.
Main Function
Parameters: None
Return: None
The entry point into the program. The function defines the overall program loop. It calls run_game and prints out who won the game. It also asks the user if he/she wants to play again, and if yes, runs the game again.
run_game
Parameters: None
Return: integer
This function defines the code that executes each round of the game. This function calls the other functions below to tie the game together. This function should return 1 if the player won or 2 if the computer won back to main.
get_player_choice
Parameters: None
Return: integer
Displays the following menu to the user:
What do you choose?
1.Rock
2.Paper
3.Scissors
It will ask the user for a number, and if the number is 1, 2, or 3, it will return the users number. It will otherwise output Error! Please choose a value between 1 and 3. and ask the user for a new number.
get_com_choice
Parameters: None
Return: integer
Returns a random integer between 1 and 3.
determine_winner
Parameters: player:integer, com:integer
Return: integer
Compares the players choice of Rock, Paper, Scissors to the computers and determines a winner. It returns 1 if the player won and 2 if the computer won. If there is a tie, it will return 0.
str_choice
Parameters: choice:integer
Return: string
Converts the number representation of Rock, Paper, or Scissors to a string. This will be used when outputting to the user what the user and computer chose. If choice is 1, the function returns Rock as a string. If choice is 2, the function returns Paper as a string .If choice is 3, the function returns Scissors as a string. If choice is neither of the above, it returns
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
