Question: # ! / usr / bin / env pythonimport matplotlib.pyplot as pltimport sysfrom optparse import OptionParserimport randomimport mathbounds _ values = range ( 0 ,
#usrbinenv pythonimport matplotlib.pyplot as pltimport sysfrom optparse import OptionParserimport randomimport mathboundsvalues rangevalidfractions for bound in boundsvalues: # Run relocation.py with bound value and capture valid fraction # Here we assume capturefraction is a function that runs relocation.py and returns the valid fraction fraction capturefractionbound validfractions.appendfractionpltplotboundsvalues, validfractionspltxlabelBounds Register Value'pltylabelFraction of Valid Addresses'plttitleFraction of Valid Virtual Addresses vs Bounds Register Value'pltshowdef convertsize: length lensize lastchar sizelength if lastchar k or lastchar K: m nsize intsize:length m elif lastchar m or lastchar M: m nsize intsize:length m elif lastchar g or lastchar G: m nsize intsize:length m else: nsize intsize return nsize# main programparser OptionParserparseraddoptionsseed', default help'the random seed', action'store', type'int', dest'seed'parseraddoptionaasize', defaultk help'address space size egkmg action'store', type'string', dest'asize'parseraddoptionpphysmem', defaultk help'physical memory size egkmg action'store', type'string', dest'psize'parseraddoptionnaddresses', default help'number of virtual addresses to generate', action'store', type'int', dest'num'parseraddoptionbb default help'value of base register', action'store', type'string', dest'base'parseraddoptionll default help'value of limit register', action'store', type'string', dest'limit'parseraddoptionccompute', defaultFalse, help'compute answers for me action'storetrue', dest'solve'options args parser.parseargsrandomseedoptionsseedasize convertoptionsasizepsize convertoptionspsizeif psize : printError: must specify a nonzero physical memory size. exitif asize : printError: must specify a nonzero addressspace size. exitif psize asize: printError: physical memory size must be GREATER than address space size for this simulation exitlimit convertoptionslimitbase convertoptionsbaseif limit : limit intasize asize random.randomif base : done while done : base intpsize random.random if base limit psize: done validcount for i in range options.num: vaddr intasize random.random if vaddr limit: validcount fractionvalid validcount options.numprintfSeed: optionsseed Limit: limit Fraction of valid addresses: fractionvalid:f
Getting errors in the code please help
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
