I'm new here, and also new to programming. I'm hoping that someone here will help me with this problem. I'm doing an online Python course at http://cscircles.cemc.uwaterloo.ca/15a-basic/
, and I'm really, really stuck.It has asked me to create a Python simulator of a BASIC program, and has split it into 3 parts for me. This is the part that I'm stuck on:
Define a function findLine(prog, target) to perform the following. Assume prog is a list of strings containing a BASIC program, like the type generated by getBASIC(); assume target is a string containing a line number, which is the target of a GOTO statement. The function should return the index i (a number between 0 and len(prog)-1) such that prog[i] is the line whose label equals target.
Sample input/output: If you call
findLine(['10 GOTO 20','20 END'], '10')
then the output should be 0, since item 0 of the list is the line with label 10.
It also gives a hint 'You will have to use split()'. Surely I will have to use more methods though? prog.split() doesn't work because prog is a list. And converting prog to a string and then using prog.split() just returns prog in the same way that it started. I'm very confused. I'm not asking anyone to solve the problem for me, because then I wouldn't learn anything. Just a nudge in the right direction would be nice, a hint or two.
I would really appreciate it if someone could help me,