fork download
  1. def getAverage(die, numRolls, numTrials):
  2. """
  3. - die, a Die
  4. - numRolls, numTrials, are positive ints
  5. - Calculates the expected mean value of the longest run of a number
  6. over numTrials runs of numRolls rolls, and the 95% confidence interval.
  7. Rounds the mean and confidence interval to 3 decimal places.
  8. - Calls makeHistogram to produce a histogram of the longest runs for all
  9. the trials. There should be 10 bins in the histogram
  10. - Choose appropriate labels for the x and y axes.
  11. - Returns the mean calculated
  12. """
  13. # TODO
  14. rolls = [0] * 6
  15. for i in range(0, numRolls):
  16. roll=int(random.randint(1,6))
  17. rolls[roll - 1] += 1
  18.  
  19. pylab.hist(die, bins=10)
  20. pylab.xlabel('numTrials')
  21. pylab.ylabel('numRolls')
  22. #pylab.title(title)
  23. pylab.show()
  24. return getMean(rolls)
Success #stdin #stdout 0.06s 62940KB
stdin
Standard input is empty
stdout
Standard output is empty