infinite loop - Python BASIC simulator -


i'm brand new programming , have been working on free python course university of waterloo. i'm stuck on section 15a, have write basic simulator. i'm working on section titled "smart simulation", i'm writing code execute basic program.

part of exercise having determine if program completed successfully, or if entered infinite loop. here current code have section:

def findline(prog, target):    x in range(0,len(prog)):       prog2 = prog[x].split()       start = prog2[0]       if len(prog2) > 2:          end = prog2[2]       if start == target:          return x   def execute(prog):    location = 0    visited = [false] * len(prog)    while true:       if location==len(prog)-1: return "success"       if visited[location] == true: return "infinite loop"       currentline = prog[location]       currentline = currentline.split()       t = currentline[2]       location = findline(prog, t)       visited[location] = true 

so i've run code through python visualizer, , problem i'm having is return infinite loop when should returning success. automated grader has, far, tested code following 2 inputs:

execute(['10 goto 21', '21 goto 37', '37 goto 21', '40 end']) results in correct answer of "infinite loop", second input of execute(['5 goto 30', '10 goto 20', '20 goto 10', '30 goto 40', '40 end']) returning "infinite loop", though should return "success".

there may better ways determine if program looping, i've followed hints course has given me setting up, , i'd able complete way expect me to. appreciate input might have this! i've been stuck on , experimenting time , i'm pulling hair out because can't figure out make work. that's offered! :)

you did it!

you misplaced assignment order, should like:

  t = currentline[2]   visited[location] = true   location = findline(prog, t) 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -