(*Copy and paste this program into a new Mathematica workbook*) (*Below is the program for CoinTosses. It takes a number (n) and a \ value (True) as input and returns the results of an experiment in \ which a coin was flipped n times (i.e. a string of H's and T's) as \ well as the proportion of times that the coin landed heads*) Clear[CoinTosses]; CoinTosses[n_, print_] := Block[ {headcounter = 0, outputstring = ""}, For[i = 1, i <= n, i++, If[(Random[] < .5), headcounter++; If[print, outputstring = StringInsert[outputstring, "H", i] ], If[print, outputstring = StringInsert[outputstring, "T", i] ] ] ]; Print[outputstring]; Print[" "]; Print["The proportion of heads in ", n, " tosses is ", N[headcounter/n, 5] ] ] (*Examples*) CoinTosses[10, True] CoinTosses[100, True] CoinTosses[1000, True] CoinTosses[10000, True]