stochastic programsprobabilityand statistics 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(fracheadsreturn mean figure flipping coin try executing the function flipsim( couple of times here' what we saw the first two times we tried itflipsim( flipsim( it seems that it would be inappropriate to assume much (other than that the coin has both heads and tailsfrom any one trial of flips that' why we typically structure our simulations to include multiple trials and compare the results let' try flipsim( )flipsim( flipsim( intuitivelywe can feel better about these results how about flipsim( )flipsim( flipsim( this looks really good (especially since we know that the answer should be but that' cheatingnow it seems we can safely conclude something about the next flipi that heads and tails are about equally likely but why do we think that we can conclude thatwhat we are depending upon is the law of large numbers (also known as bernoulli' theorem this law states that in repeated independent experiments ( flipping fair coin times and counting the fraction of headswith the same expected value ( in this case)the average value of the though the law of large numbers had been discussed in the th century by cardanothe first proof was published by jacob bernoulli in the early th century it is unrelated to the theorem about fluid dynamics called bernoulli' theoremwhich was proved by jacob' nephew daniel