random walks and more about data vizualization class field(object)def __init__(self)self drunks {def adddrunk(selfdrunkloc)if drunk in self drunksraise valueerror('duplicate drunk'elseself drunks[drunkloc def movedrunk(selfdrunk)if drunk not in self drunksraise valueerror('drunk not in field'xdistydist drunk takestep(currentlocation self drunks[drunk#use move method of location to get new location self drunks[drunkcurrentlocation move(xdistydistdef getloc(selfdrunk)if drunk not in self drunksraise valueerror('drunk not in field'return self drunks[drunkfigure field class the classes drunk and usualdrunk define the ways in which drunk might wander through the field in particular the value of stepchoices in usualdrunk restores the restriction that each step is of length one and is parallel to either the -axis or -axis it also captures the assumption that each kind of step is equally likely and not influenced by previous steps bit later we will look at subclasses of drunk with different kinds of behaviors class drunk(object)def __init__(selfname none)"""assumes name is str""self name name def __str__(self)if self !nonereturn self name return 'anonymousclass usualdrunk(drunk)def takestep(self)stepchoices [( , )( ,- )( )(- )return random choice(stepchoicesfigure drunk base class the next step is to use these classes to build simulation that answers the original question figure contains three functions used in this simulation the function walk simulates one walk of numsteps steps the function simwalks calls walk to simulate numtrials walks of numsteps steps each the function drunktest calls simwalks to simulate walks of varying lengths