def getfinallocs(numstepsnumtrialsdclass)locs [ dclass(origin location( for in range(numtrials) field( adddrunk(doriginfor in range(numsteps) movedrunk(dlocs append( getloc( )return locs def plotlocs(drunkkindsnumstepsnumtrials)stylechoice styleiterator((' +'' ^''mo')for dclass in drunkkindslocs getfinallocs(numstepsnumtrialsdclassxvalsyvals [][for in locsxvals append( getx()yvals append( gety()meanx sum(xvals)/float(len(xvals)meany sum(yvals)/float(len(yvals)curstyle stylechoice nextstyle(pylab plot(xvalsyvalscurstylelabel dclass __name__ mean loc <str(meanx'str(meany'>'pylab title('location at end of walks (str(numstepssteps)'pylab xlabel('steps east/west of origin'pylab ylabel('steps north/south of origin'pylab legend(loc 'lower left'numpoints plotlocs((usualdrunkcolddrunkewdrunk) figure plotting final locations the first thing plotlocs does is initialize stylechoice with three different styles of markers it then uses pylab plot to place marker at location corresponding to the end of each trial the call to pylab plot sets the color and shape of the marker to be plotted using the values returned by the iterator styleiterator the call plotlocs((usualdrunkcolddrunkewdrunk) produces the plot on the right the first thing to say is that our drunks seem to be behaving as advertised the ewdrunk ends up on the -axisthe colddrunk seem to make progress southwardsand the usualdrunk seem to have wandered aimlessly