import random


def rollDie():
    return random.choice([1, 2, 3, 4, 5, 6])


def rollN(n):
    result = ''
    for i in range(n):
        result += str(rollDie())
    return result

print('5 random rolls of a Die:', rollN(5))


def getTarget(goal):
    numTries = 0
    numRolls = len(goal)
    while True:
        numTries += 1
        result = rollN(numRolls)
        if result == goal:
            return numTries


def runSim(goal, numTrials):
    total = 0
    for i in range(numTrials):
        total += getTarget(goal)
    # print 'Average number of tries =', total / float(numTrials)
    print('Probability =', 1 / (total / float(numTrials)))

print('Probability =', 0.0001286)
runSim('11111', 100)
runSim('54324', 100)


def atLeastOneOne(numRolls, numTrials):
    numSuccess = 0
    for i in range(numTrials):
        rolls = rollN(numRolls)
        if '1' in rolls:
            numSuccess += 1
        fracSuccess = numSuccess / float(numTrials)
    print(fracSuccess)

atLeastOneOne(10, 1000)