stochastic programsprobabilityand statistics def flipplot(minexpmaxexp)"""assumes minexp and maxexp positive integersminexp maxexp plots results of **minexp to **maxexp coin flips""ratios [diffs [xaxis [for exp in range(minexpmaxexp )xaxis append( **expfor numflips in xaxisnumheads for in range(numflips)if random random( numheads + numtails numflips numheads ratios append(numheads/float(numtails)diffs append(abs(numheads numtails)pylab title('difference between heads and tails'pylab xlabel('number of flips'pylab ylabel('abs(#heads #tails)'pylab plot(xaxisdiffspylab figure(pylab title('heads/tails ratios'pylab xlabel('number of flips'pylab ylabel('#heads/#tails'pylab plot(xaxisratiosrandom seed( flipplot( figure plotting the results of coin flips the call flipplot( produces the two plotsthe plot on the left seems to suggest that the absolute difference between the number of heads and the number of tails fluctuates in the beginningcrashes downwardsand then moves rapidly upwards howeverwe need to keep in mind that we have only two data points to the right of , that pylab plot connected these points with lines may mislead us into seeing trends when all we have are isolated points this is not an uncommon phenomenonso you should always ask how many points plot actually contains before jumping to any conclusion about what it means