Question: need your help on this: # Dice - count totals in user-defined number of rounds import random class Bin(): def __init__(self, binIdentifier): # This method

need your help on this:

# Dice - count totals in user-defined number of rounds

import random

class Bin(): def __init__(self, binIdentifier): # This method runs whenever you create a Bin object self.number = identifier self.count = 0 def reset(self): # This is called when you start or restart self.count = 0

def increment(self): # Called when the roll total is the value of the binIdentifier self.count += 1

def show(self, total_rolls): # Called at the end to show the contents of this bin percent = round((self.count * 100)/total_rolls) print(str(self.number) + ": " + percent * "*" + " " + str(percent) + "% (" + str(self.count) + ")") if __name__ == "__main__":

#MIN_ROLL = 2 #MAX_ROLL = 12 # Build a dict of Bin objects binDict = {} # start off as the empty dict # In the loop, create a Bin object # Add to dict, rollTotal is the key, the Bin object is the value

while True: nRounds = input('How many rounds do you want to do? (or Enter to exit): ') if nRounds == '': break nRounds = int(nRounds)

# Tell each bin object to reset itself for oBin in binDict.values(): oBin.reset() # For each round (build a loop): # roll two dice # calculate the total # and tell the appropriate bin object to increment itself

print() print('After', nRounds, 'rounds:') # Tell each bin to show itself for oBin in binDict.values(): oBin.show(nRounds) print()

print('OK bye')

===result likes this:

How many rounds do you want to do? (or Enter to exit): 1000000

After 1000000 rounds: 2 : count is 28012 or 2 % 3 : count is 55665 or 5 % 4 : count is 83513 or 8 % 5 : count is 110874 or 11 % 6 : count is 138351 or 13 % 7 : count is 166296 or 16 % 8 : count is 139313 or 13 % 9 : count is 110814 or 11 % 10 : count is 83521 or 8 % 11 : count is 55792 or 5 % 12 : count is 27849 or 2 %

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!