Harvard:Biophysics 101/2007/02/06:coinflip.py: Difference between revisions

From OpenWetWare
Jump to navigationJump to search
mNo edit summary
mNo edit summary
 
Line 12: Line 12:
tally = [0 for i in range(11)]
tally = [0 for i in range(11)]


for i in range(1000):
for i in range(10000):
     coinflip = ### Generate the random 10-mer of H's and T's ###
     coinflip = ### Generate the random 10-mer of H's and T's ###



Latest revision as of 12:47, 6 February 2007

Biophysics 101: Genomics, Computing, and Economics

Home        People        Schedule        Project        Python        Help       

Here is some template code to get you started. Replace the ### comments ### with code to complete the assignment

#!/usr/bin/env python

import random

# make a list of values for each 
tally = [0 for i in range(11)]

for i in range(10000):
    coinflip = ### Generate the random 10-mer of H's and T's ###

    # Use this loop to tally up instances of each k-mer (from 2 to 10)
    for k in range(2,11):
        # store a k-mer of H's
        H = ''.join(['H' for n in range(k)])
        Hcount = 0

        ### Count up the number of "H" k-mers in this coinflip ###
        ### See Feb6 assignment for example ###

        # Update the tally for this k-mer
        tally[k] = tally[k] + Hcount


        T = ''.join(['T' for n in range(k)])
        Tcount = 0

        ### Repeat the above for T's ###

        tally[k] = tally[k] + Tcount        

# print out the results
for i in range(2,11):
    print i, tally[i]