have written this rock, scissors, and paper game code and it runs fine. but I need a two dimensional array that have to keep and print a record of the games played, which would say how many times the user won, how many times the computer won and how many times the games were tied, could you help me with this please?   This is the code that need the two dimensional array mentioned above, don't forget the indents: import random print("Let's play the Rock Paper Scissors game!") def playerchoice(): ## Error Trap for choice while True: print("Rock = 1\nPaper = 2\nScissors = 3") try: player = int(input("Choose your move: ")) if player <= 0 or player >= 4: raise ValueError("Wrong move! Please choose 1, 2, or 3") else: return player except ValueError as wrongmsg: print(wrongmsg) ## Comparing choice with a function def result(player,computer): if player == computer: print("Computer chose",player,"\nTie Game") return 0 if player == 1 and computer == 3: print("Computer chose 3\nPlayer won") return 1 if player == 1 and computer == 2: print("Computer chose 2\nComputer won") return 2 if player == 2 and computer == 1: print("Computer chose 1\nPlayer won") return 1 if player == 2 and computer == 3: print("Computer chose 3\nComputer won") return 2 if player == 3 and computer == 2: print("Computer chose 2\nPlayer won") return 1 if player == 3 and computer == 1: print("Computer chose 1\nComputer won") return 2   PlayAgainNpt = "y" player_score = 0 computer_score = 0 total_games = [] game_count = 0 tie_games = 0 while True: player_choice = playerchoice() ## Computer will randomly choose a move computer_choice = random.randint(1,3) res = result(player_choice,computer_choice) toAppend = (1,0) if res == 1: player_score +=1 if res == 2: computer_score +=1 if res == 0: tie_games +=1 game_count +=1 total_games.append([game_count, toAppend]) PlayAgainNpt = input("Do you want to play again?(y/n): ") if PlayAgainNpt == "n": print("\nTotal games played:",game_count) print("Scores") print("Player won:",player_score) print("Computer won:",computer_score) print() break

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter8: Arrays
Section: Chapter Questions
Problem 7RQ
icon
Related questions
Question

I have written this rock, scissors, and paper game code and it runs fine. but I need a two dimensional array that have to keep and print a record of the games played, which would say how many times the user won, how many times the computer won and how many times the games were tied, could you help me with this please?

 

This is the code that need the two dimensional array mentioned above, don't forget the indents:

import random

print("Let's play the Rock Paper Scissors game!")

def playerchoice():
## Error Trap for choice
while True:

print("Rock = 1\nPaper = 2\nScissors = 3")

try:

player = int(input("Choose your move: "))
if player <= 0 or player >= 4:
raise ValueError("Wrong move! Please choose 1, 2, or 3")

else:
return player
except ValueError as wrongmsg:
print(wrongmsg)

## Comparing choice with a function
def result(player,computer):
if player == computer:

print("Computer chose",player,"\nTie Game")
return 0
if player == 1 and computer == 3:
print("Computer chose 3\nPlayer won")
return 1
if player == 1 and computer == 2:
print("Computer chose 2\nComputer won")
return 2
if player == 2 and computer == 1:
print("Computer chose 1\nPlayer won")
return 1
if player == 2 and computer == 3:
print("Computer chose 3\nComputer won")
return 2
if player == 3 and computer == 2:
print("Computer chose 2\nPlayer won")
return 1
if player == 3 and computer == 1:
print("Computer chose 1\nComputer won")
return 2

 


PlayAgainNpt = "y"
player_score = 0
computer_score = 0
total_games = []
game_count = 0
tie_games = 0
while True:
player_choice = playerchoice()

## Computer will randomly choose a move
computer_choice = random.randint(1,3)

res = result(player_choice,computer_choice)
toAppend = (1,0)
if res == 1:
player_score +=1
if res == 2:
computer_score +=1
if res == 0:
tie_games +=1
game_count +=1
total_games.append([game_count, toAppend])
PlayAgainNpt = input("Do you want to play again?(y/n): ")
if PlayAgainNpt == "n":
print("\nTotal games played:",game_count)
print("Scores")
print("Player won:",player_score)
print("Computer won:",computer_score)
print()
break

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT