import random class twoDice(): # constructor def __init__(self, a = 6, b = 6): self.sides1 = a self.sides2 = b self.previousRolls = [] # Method that rolls the two dice and returns the sum of the outcomes def roll(self): (self.previousRolls).append(random.randint(1, self.sides1) + random.randint(1, self.sides2)) # return self.previousRolls[-1] return self.mostRecentRoll() # return the value of the most recent roll def mostRecentRoll(self): return self.previousRolls[-1] # returns the list consisting of the most recent n rolls def previousRoll(self, n): return self.previousRolls[len(self.previousRolls)-n:] # returns the average roll value based on all the rolls thus far def meanRoll(self): return sum(self.previousRolls)*1.0/len(self.previousRolls)