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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education