Respuesta :
Answer:
import random
def getComputerChoice(num):
if num == 1:
return "rock"
if num == 2:
return "paper"
return "scissor"
def main():
name = input("Enter your name: ")
rounds = 0
com_wins = 0
user_wins = 0
while True:
print("\n1.Rock")
print("2.Paper")
print("3.Scissor")
user = int(input("Enter choice: "))
rounds += 1
while user<=0 or user>3:
print("Invalid choice")
user = int(input("Enter choice: "))
computer_choice = random.randint(1,3)
# This is for handling tie
while computer_choice == user:
computer_choice = random.randint(1,3)
print("Computer has chosen ->",getComputerChoice(computer_choice))
if (computer_choice==1 and user==2) or (computer_choice==2 and user==1):
print("paper beats rock")
winner = 2
elif (computer_choice==3 and user==1) or (computer_choice==1 and user==3):
print("rock beats scissor")
winner = 1
else:
print("scissors beat paper")
winner = 3
if winner == user:
print(name,"wins!!!")
user_wins += 1
else:
print("Computer wins!!!")
com_wins += 1
play = input("Do you want to play again?(Y/N) ")
if play == 'n' or play == 'N':
break
print("No of rounds played:",rounds)
print("Computer won:", com_wins)
print(name,"won:",user_wins)
main()