asweigart

milliondicestats.py

May 12th, 2021 (edited)
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. import random
  2.  
  3. print('Million Dice Roll Statistics Simulator')
  4. print('Enter how many six-sided dice you want to roll:')
  5. numberOfDice = int(input('> '))
  6.  
  7. # Set up a dictionary to store the results of each dice roll:
  8. results = {}
  9. for i in range(numberOfDice, (numberOfDice * 6) + 1):
  10.     results[i] = 0
  11.  
  12. # Simulate dice rolls:
  13. print('Simulating 1,000,000 rolls of', numberOfDice, 'dice...')
  14. for i in range(1000000):
  15.     if i % 100000 == 0:
  16.         print(round(i / 10000, 1), '% done...')
  17.  
  18.     total = 0
  19.     for j in range(numberOfDice):
  20.         total = total + random.randint(1, 6)
  21.     results[total] = results[total] + 1
  22.  
  23. # Display results:
  24. print('TOTAL - ROLLS - PERCENTAGE')
  25. for i in range(numberOfDice, (numberOfDice * 6) + 1):
  26.     roll = results[i]
  27.     percentage = round(results[i] / 10000, 1)
  28.     print(i, ' - ', roll, 'rolls -', percentage, '%')
  29.  
Add Comment
Please, Sign In to add comment