def flip(numflips)heads for in range(numflips)if random random( heads + return heads/numflips def flipsim(numflipspertrialnumtrials)fracheads [for in range(numtrials)fracheads append(flip(numflipspertrial)mean sum(fracheads)/len(fracheadssd stddev(fracheadsreturn (fracheadsmeansddef labelplot(numflipsnumtrialsmeansd)pylab title(str(numtrialstrials of str(numflipsflips each'pylab xlabel('fraction of heads'pylab ylabel('number of trials'xminxmax pylab xlim(yminymax pylab ylim(pylab text(xmin (xmax-xmin)* (ymax-ymin)/ 'mean str(round(mean )'\nsd str(round(sd ))size=' -large'def makeplots(numflips numflips numtrials)val mean sd flipsim(numflips numtrialspylab hist(val bins xmin,xmax pylab xlim(ymin,ymax pylab ylim(labelplot(numflips numtrialsmean sd pylab figure(val mean sd flipsim(numflips numtrialspylab hist(val bins pylab xlim(xminxmaxlabelplot(numflips numtrialsmean sd random seed( makeplots( , , figure plot histograms demonstrating normal distributions when the code in figure is runit produces the plots