#Illustrating the plotting library with some simulations #involving coin-tossing. #This code uses the pylab plotting functions. You have a choice #between using standard Python lists and using the enhanced #array manipulation functions in numpy. This code illustrates #both approaches. from pylab import * #Caution: Some people object to importing the #pylab package in this way. The advantage is that #you do not have to write the library name every time #you invoke a function, but you can sometimes run into #the problem of colliding namespaces. It is probably #more prudent to type 'import pylab' and invoke each #function with the 'pylab.' prepended. #Simulated coin tosses: return a Python list of booleans, representing the #result of n tosses of a coin with heads probability p. def coins(p,n): """Returns a list of n tosses of a coin with Heads probability p. The return value is a list of booleans, with True denoting Heads""" tosses=[] for j in range(n): tosses.append(rand()