# betterDiceThrowing.py

# Here we improve on diceThrowing.py by realizing that we can
# compute the odds for all the totals at once, rather than
# repeating our trials for each possible total.

import random

def rollDie(sides):
    return random.randint(1,sides)

def rollDice(dice, sides):
    dieTotal = 0
    for roll in range(dice):
        die = rollDie(sides)
        dieTotal += die
    return dieTotal

def diceOdds(dice, sides):
    trials = 1000*100
    maxTotal = dice*sides
    successes = [0]*(maxTotal+1)
    for trial in range(trials):
        dieTotal = rollDice(dice, sides)
        successes[dieTotal] += 1
    odds = [count/trials for count in successes]
    return odds

def printAllDiceOdds(dice, sides):
    oddsList = diceOdds(dice, sides)
    for total in range(dice,dice*sides+1):
        odds = 100*oddsList[total]
        print(f'{total} {odds:6.2f}')

printAllDiceOdds(3,3)