Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Docs needed: https://drive.google.com/open?id=1-4kP1arb5jNOT2At6a89smZazunrhKyX

ID: 3712627 • Letter: D

Question

Docs needed:

https://drive.google.com/open?id=1-4kP1arb5jNOT2At6a89smZazunrhKyX

https://drive.google.com/open?id=1d8E9vjbcOTpXtY22342j-zmVoXH-IH1B

points) Even Game - Write a game that tracks how many rolls of 4 die results in an even value of the total of roll. The game must use the Die and DieShaker classes from Part 1 and 2 (15 points will be deducted if not used properly!). Here are the methods -init-0: Constructor. Dice roll0 : Shakes the DiceShaker and used to retrieve the count of the die values See messages below a. Initializes the class and creates a DiceShaker with 4 b. c. getTotalGames0: returns an int with the total games played (calls to rollO) d. getGamesWon0: returns an int with the total of games that resulted in even number results getScoreMessage): returns a string with the status of games won vs played (see string below) e. >>e-EvenGame () >>> e.roll () You won You rolled a 14 which is an even number >>> e.roll () You won You rolled a 16 which is an even number >>> e.roll () Sorry. You rolled a 19 which is not an even number >>> e.getscoreMessage () 'You have won 2 out of 3 games' >>> e . getTota|Games ( ) >>> e . getGamesWon ( ) >>> e.roll () You won You rolled a 14 which is an even number >>> e.roll () Sorry. You rolled a 23 which is not an even number >>> e.roll () Sorry. You rolled a 19 which is not an even number >e.getTotalGames () >>> e.getGamesWon () >>> e.getscoreMessage () 'You have won 3 out of 6 games'

Explanation / Answer

#EvenGame.py

import random
class Die(object):
def __init__(self, dieSides=6):
self.dieSides = dieSides
self.roll()
def roll(self):
self.value = random.randrange(self.dieSides) + 1
return self.value
def get(self):
return self.value
class DiceShaker(object):
'DiceShaker class'
def __init__(self,dieCount=1, dieSides=6):
self.dieCount = dieCount
self.dieSides = dieSides
self.dices = [Die(dieSides) for i in range(dieCount)]
  
def shake(self):
for die in self.dices:
die.roll()
  
def getTotalRoll(self):
total = 0
for die in self.dices:
total += die.get()
return total
  
def getIndividualRolls(self):
return [die.get() for die in self.dices]

def __str__(self):
string = ""
rolls = self.getIndividualRolls()
for roll in rolls:
string += str(roll) + " "
return string


class EvenGame(object):
def __init__(self):
self.shaker = Diceshaker(4)
self.roll()
self.gameCount = 0
self.winCount = 0

def roll(self):
self.shaker.shake()
rolls = sh.getIndividualRolls()
total = sum(rolls)
self.gameCount += 1
if sum % 2 == 0:
print("You won! You rolled a %d which is an even number." % (total))
self.winCount += 1
else:
print("Sorry. You rolled a %d which is not an even number." % (total))

def getScoreMessage(self):
return 'You have won ' + str(self.getGameWon()) + " out of " + str(self.getTotalWon) + " games"

def getTotalWon(self):
return self.gameCount
def getGameWon(self):
return self.winCount

# copy pastable code link: https://paste.ee/p/INvQB

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote