Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- print('Million Dice Roll Statistics Simulator')
- print('Enter how many six-sided dice you want to roll:')
- numberOfDice = int(input('> '))
- # Set up a dictionary to store the results of each dice roll:
- results = {}
- for i in range(numberOfDice, (numberOfDice * 6) + 1):
- results[i] = 0
- # Simulate dice rolls:
- print('Simulating 1,000,000 rolls of', numberOfDice, 'dice...')
- for i in range(1000000):
- if i % 100000 == 0:
- print(round(i / 10000, 1), '% done...')
- total = 0
- for j in range(numberOfDice):
- total = total + random.randint(1, 6)
- results[total] = results[total] + 1
- # Display results:
- print('TOTAL - ROLLS - PERCENTAGE')
- for i in range(numberOfDice, (numberOfDice * 6) + 1):
- roll = results[i]
- percentage = round(results[i] / 10000, 1)
- print(i, ' - ', roll, 'rolls -', percentage, '%')
Add Comment
Please, Sign In to add comment