[ create a new paste ] login | about

Link: http://codepad.org/I3APCCox    [ raw code | fork ]

Python, pasted on Dec 16:
import random

def flip():
    if random.random() > 0.5:
        flip1 = 'H'
    else:
        flip1 = 'T'
    return flip1

def bunchOfFlips(howMany):
    totals = []
    ratios = []
    ratio = 0
    heads = 0
    tails = 0
    for i in range(howMany):
        totals.append(flip())
    for i in totals:
        if i == 'H':
            heads += 1
        elif i == 'T':
            tails += 1
    ratio = heads/float(tails)
    print 'Number of Heads =' + ' ' + str(heads),'\n' 'Number of Tails =' + ' ' + str(tails)
    print 'Ratio of Heads to Tails =' + ' ' +str(ratio)


Output:
No errors or program output.


Create a new paste based on this one


Comments: