# This program simulates flipping a coin 1000 times and # counts the number of flips which come out heads. How far # away from the expected number of 500 is the actual result? # Try running this program a bunch of times in order to see # the distribution. import random def makestr(n): return [random.randint(0,1) for _ in xrange(n)] def numheads(s): count = 0 for i in range(len(s)): if s[i] == 1: count += 1 return count s = makestr(1000) print numheads(s)