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.
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()
Get Answers For Free
Most questions answered within 1 hours.