tuation We leave this problem for you to solve we give a hin
tuation. We leave this problem for you to solve; we give a hint below. Coding Exercise: Smart Simulation write a tion execute prog) to do the following. Assume prog is a list of strings containing the BASIC program, like before. Then, your function should return either success\" or \"infinite loop depending on whether the program terminates or loops forever. Important you should assume the procedure findLineCprog, target) defined in sub-task 2 is already defined, you do not need to re-write it. Hint 1 def execute(prog): 2 location 0 3 counter 4 while True find T prog Ilocation].split T find TC-1] location findLineCprog T) counter 1 if T END return \"success\" if counter len(prog): return \"infinite loop\" Visualize Open in console Enter test statements Run program More actions... Putting it all together To test your code as a complete solution, copy and paste your previous solutions into the following template. Coding Exercise: BASIC Simulator

Solution
print(execute(getBASIC()))
| # def getBASIC from subtask 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def getBASIC(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| b=[] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| while True: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| a=input() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| b.append(a) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if a.endswith(\"END\") == True: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return b | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # def findLine from subtask 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def findLine(prog, target): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for i in prog: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| x=i.split() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if x[0] == target: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return prog.index(i) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # def execute from subtask 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def execute(prog): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| c=prog[-1].split() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| d=0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for location in range(0, len(prog)-1): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| T=prog[location] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if c[0] in T: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| d=d+1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if d==1: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return \"success\" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return \"infinite loop\" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print(execute(getBASIC()))
|

