In PYTHON 3 implement function simul that takes as input an
In PYTHON 3 implement function simul() that takes as input an integer n and simulates n rounds
of Rock, Paper, Scissors between players Player 1 and Player 2. The player who wins the
most rounds wins the n-round game, with ties possible. Your function should print the result
of the game as shown.
>>> simul(1)
Player 1
>>> simul(1)
Tie
>>> simul(100)
Player 2
Solution
The program for the above scenario is:
def rps(p1,p2):
#tie
if (p1==p2):
return 0
# player 1 wins
elif p1+p2 in [\'PR\',\'RS\',\'SP\']:
return -1
else:
return 1
# player 2 wins
def choose_rps():
import random
random.choice(\'RPS\')
def simul(n):
score = 0
for i in range(n):
p1 = choose_rps()
p2 = choose_rps()
result = rps(p1, p2)
score += result
if score < 0:
print(\'Player 1\')
elif score == 0:
print(\'Tie\')
