Python 3 - BASIC Simulator -


i'm working on basic simulator in python, title suggests. program should either print "success" or "infinite loop", depending on 1 true. here code:

def findline(prog, target):    l in range(0, len(prog)):       progx = prog[l].split()       if progx[0] == target:           return l   def execute(prog):   location = 0   while true:     if location==len(prog)-1: return "success"     else: return "infinite loop"     t = prog.split()[location]     location = findline(prog, t) 

findline should take input this: findline(['10 goto 20', '20 end'], '20') , output index of prog in target appears.
execute should take input this: execute(['10 goto 21', '21 goto 37', '37 goto 21', '40 end'])

problem is, "def execute(prog)" portion of code broken, , need fixing describe earlier. debugging appreciated, , apologies if little vague -- i'm not quite sure write.

you should try execute code step step in debugger see happens. or mentally.

first, set location 0. then, if equals number of lines. if so, return success, if not, return infinite loop. how expect next 2 lines executed?

i think should redesign way detect infinite loop. not being on last line isn't sufficient condition... if interpreter handles goto, reaching same line 2 times hint. if implement more logic, should think detecting number of times reach each line, , set threshold on that.


Comments

Popular posts from this blog

asp.net mvc 3 - Using mvc3, I need to add a username/password to the sql connection string at runtime -

kineticjs - draw multiple lines and delete individual line -

thumbnails - jQuery image rotate on hover -