# diceThrowing.py

# For correct answers, try here:
# http://www.ogmiosproject.org/articles/stattables.html

import random

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

def trialSucceeds(dice, sides, total):
    # run only ONE trial and return True on success.
    # one trial means:
    # roll 2 dice and succeed if their sum is total
    dieTotal = 0
    for roll in range(dice):
        die = rollDie(sides)
        dieTotal += die
    return (dieTotal == total)

def diceOdds(dice, sides, total, trials):
    successes = 0
    for trial in range(trials):
        if trialSucceeds(dice, sides, total) == True:
            successes += 1
    return successes / trials

def printAllDiceOdds(dice, sides):
    # print the label line
    print('Trials', end='')
    for label in range(dice, dice*sides+1):
        print(f'{label:7}', end='')
    print()
    # now compute and print results for different-sized trials
    for k in range(1,6):
        trials = 10**k
        print(f'{trials:7}', end='')
        for total in range(dice, dice*sides+1):
            odds = 100*diceOdds(dice, sides, total, trials)
            print(f'{odds:6.2f} ', end='')
        print()

printAllDiceOdds(3,3)
