Question

In this question you will write a function that determines the result of a rock, paper,...

In this question you will write a function that determines the result of a rock, paper, scissors game given choices of player 1 and player 2. In particular, write a function rps_winner() that prompts the user for choice of player 1 and then choice of player 2, and then it displays the result for player 1 as indicated in the examples given in Section 2. You may assume that the user will only enter words: rock, paper or scissors in lower case. Recall that paper beats rock, that rock beats scissors and that scissors beat paper. If both players make the same choice, we have a draw.

Could you help me this with using python? I can't use loop or if statement for this question.

Homework Answers

Answer #1

Code --------------------------------------------------------------------------------------

def rps_winner():

    # take input from the user

    p_1 = str(input())

    p_2 = str(input())

    # to tackle the problem of not able to use a if statement

    # we create a dictionary of dictionary which takes in p_1, p_2 as it's input indix to give the output

    # dictionay that gives the result based on p_2 if p_1 is 'rock'

    res_rock = {'rock' : 'draw', 'paper' : 'Player 1 loses', 'scissors' : 'Player 1 wins'}

    # dictionay that gives the result based on p_2 if p_1 is 'paper'

    res_paper = {'rock' : 'Player 1 wins', 'paper' : 'draw', 'scissors' : 'Player 1 loses'}

    # dictionay that gives the result based on p_2 if p_1 is 'scissors'

    res_scissors = {'rock' : 'Player 1 loses', 'paper' : 'Player 1 wins', 'scissors' : 'draw'}

    # dictionary of dictionaries that maps one of the previous dictionaries as output based on p_1

    res = {'rock' : res_rock, 'paper' : res_paper , 'scissors' : res_scissors}

    print(res[p_1][p_2])

#driver code

rps_winner()

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Using Java, write a program that allows the user to play the Rock-Paper-Scissors game against the...
Using Java, write a program that allows the user to play the Rock-Paper-Scissors game against the computer through a user interface. The user will choose to throw Rock, Paper or Scissors and the computer will randomly select between the two. In the game, Rock beats Scissors, Scissors beats Paper, and Paper beats Rock. The program should then reveal the computer's choice and print a statement indicating if the user won, the computer won, or if it was a tie. Allow...
Rock-Paper-Scissors The table below shows the choices made by 122 players on the first turn of...
Rock-Paper-Scissors The table below shows the choices made by 122 players on the first turn of a Rock-Paper-Scissors game. Recall that rock beats scissors which beats paper which beats rock. A player gains an advantage in playing this game if there is evidence that the choices made on the first turn are not equally distributed among the three options. Use a goodness-of-fit test to see it there is evidence that any of the proportions are different from 1 3 ....
(Game: scissor, rock, paper) Write a program that plays the popular scissor-rockpaper game. (A scissor can...
(Game: scissor, rock, paper) Write a program that plays the popular scissor-rockpaper game. (A scissor can cut a paper, a rock can knock a scissor, and a paper can wrap a rock.) The program randomly generates a number 0, 1, or 2 representing scissor, rock, and paper. The program prompts the user to enter a number 0, 1, or 2 and displays a message indicating whether the user or the computer wins, loses, or draws.
Many of you probably played the game “Rock, Paper, Scissors” as a child. Consider the following...
Many of you probably played the game “Rock, Paper, Scissors” as a child. Consider the following variation of that game. Instead of two players, suppose three players play this game, and let us call these players A, B, and C. Each player selects one of these three items—Rock, Paper, or Scissors—independent of each other. Player A will win the game if all three players select the same item, for example, rock. Player B will win the game if exactly two...
7.14 The table below shows the choices made by 119 players on the first turn of...
7.14 The table below shows the choices made by 119 players on the first turn of a Rock-Paper-Scissors game. Recall that rock beats scissors which beats paper which beats rock. A player gains an advantage in playing this game if there is evidence that the choices made on the first turn are not equally distributed among the three options. Use a goodness-of-fit test to see if there is evidence that any of the proportions are different from 1/3. Frequencies for...
R-S-P Requirement: - write one C++ program that mimics the Rock-Scissor-Paper game. This program will ask...
R-S-P Requirement: - write one C++ program that mimics the Rock-Scissor-Paper game. This program will ask user to enter an input (out of R-S-P), and the computer will randomly pick one and print out the result (user wins / computer wins). - User's input along with computer's random pick will be encoded in the following format: -- user's rock: 10 -- user's scissor:          20 -- user's paper:            30 -- comp's rock:            1 -- comp's scissor:        2 -- comp's...
Code the Rock Paper Scissors program: a. Get a move choice from player A which must...
Code the Rock Paper Scissors program: a. Get a move choice from player A which must be R, P, S or r, p, s Exit with System.exit(0) and an error msg if the user fails to respond correctly b. Get a move choice from player B in the same manner Again, Exit with System.exit(0) and an error msg if the user fails to respond correctly c. Display the results using the accepted phrases from the game Rock breaks Scissors, Paper...
Consider a modified sequential version of Paper Scissors Rock where Player 1 goes first and chooses...
Consider a modified sequential version of Paper Scissors Rock where Player 1 goes first and chooses Paper, Scissors or Rock, and Player 2 goes second and chooses Paper, Scissors, or Rock. For each player, a win gets a payoff of 1, a loss gets a payoff of -1, and a tie get a payoff of 0. (a) (9 points) Write out the entire game tree for this sequential game. (b) (4 points) Find all the subgame perfect equilibria using backwards...
The table below shows the choices made by 125 players on the first turn of a...
The table below shows the choices made by 125 players on the first turn of a Rock-Paper-Scissors game. Recall that rock beats scissors which beats paper which beats rock. A player gains an advantage in playing this game if there is evidence that the choices made on the first turn are not equally distributed among the three options. Use a goodness-of-fit test to see it there is evidence that any of the proportions are different from 1/3. Option Selected Frequency...
1. When playing Rock-Paper-Scissors, each player has the strategies Rock, Paper, and Scissors (abbreviated as R,...
1. When playing Rock-Paper-Scissors, each player has the strategies Rock, Paper, and Scissors (abbreviated as R, P, and S). What strategy did each player choose in the strategy profile (P, S), and who won? 2. When playing Rock-Paper-Scissors, each player has the strategies Rock, Paper, and Scissors (abbreviated as R, P, and S). How would Player 2's preferences rank the strategy profiles (P, R) and (S, S)? Group of answer choices They would be indifferent between (P, R) and (S,...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT