Design a python program that simulates the game rock, paper, and scissors. You are to keep track of your wins, losses, and ties. You are to allow the users to play over and over again until he or she...

1 answer below »
PFA


Design a python program that simulates the game rock, paper, and scissors.  You are to keep track of your wins, losses, and ties.  You are to allow the users to play over and over again until he or she decides to quit.  After each throw, you will display the results of the throw followed by the current win, loss, tie numbers.  A throw consists of the player picking either Rock, Paper, or Scissors followed by the computer randomly choosing Rock, Paper, or Scissors. Rules of the game: Rock beats Scissors. Paper beats Rock. Scissor beats paper. MENU: 1. Throw Rock 2. Throw Paper 3. Throw Scissors 4. Quit Sample Run: Option 1: == RESULTS == Computer Throws Scissors, you win Wins…………………...:1 Losses………………...: 0 Ties…………………..: 0 Longest Win Streak....: 1 Longest Lose Streak..: 0 Note: After each Throw you will display the results from above
Answered Same DaySep 09, 2021

Answer To: Design a python program that simulates the game rock, paper, and scissors. You are to keep track of...

Vaibhav answered on Sep 09 2021
124 Votes
# library to generate a random integer.
import random
# Global variables
# dictonary to map integer values to user choices.
choices = {
1: "Rock",
2: "Paper",
3: "S
cissor"
}
# dictonary to map int values to win/loose status.
status = {
0: "Win",
1: "Loose"
}
class Game:
""" Game class represents a single simulation of game,
where user and computer choose one option out of rock, paper and scissor.
"""
def __init__(self, choice) -> None:
""" Constructor
Args:
choice ([int]): [for current game, users choice is initalized]
"""
self.userChoice = choices[choice]
self.compChoice = None
def setcompChoice(self) -> None:
""" Generates a random choice out of 3 avaliable choices for computer
"""
self.compChoice = choices[random.randint(1, 3)]
def chooseWinner(self) -> int:
""" Rule of the game:
Rock beats Scissors.
Paper beats Rock.
Scissor beats paper.
Returns:
int: [0, if user is winner
1, if computer is winner
-1, if it's a draw]
"""
if self.userChoice == choices[1] and self.compChoice == choices[3]:
print("Computer throws {0}, you {1}".format(
self.compChoice, status[0]))
return 0
elif self.userChoice == choices[3] and self.compChoice == choices[1]:
print("Computer throws {0}, you {1}".format(
self.compChoice, status[1]))
return 1
elif self.userChoice == choices[2] and self.compChoice == choices[1]:
print("Computer throws {0}, you {1}".format(
self.compChoice, status[0]))
return 0
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here