正如标题所示,我目前正在Python中使用BASIC模拟器。这个程序应该打印“成功”或“无限循环”,这取决于哪一个是真的。这是我的代码:Python 3 - BASIC模拟器
def findLine(prog, target):
for 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应采取这样的输入:findLine([ '10 GOTO 20','20 END'], '20')和输出PROG的在其中出现靶的指标。执行(['10 GOTO 21','21 GOTO 37','37 GOTO 21','40 END'])
问题是,“def execute(prog )“这段代码的一部分被破坏了,我需要一些帮助修复它,以便它能够完成我之前描述的内容。任何帮助调试这将不胜感激,并道歉,如果这有点模糊 - 我不太确定写什么。
究竟是什么问题?你是什么意思?破* *?你能描述一下发生了什么,以及你期望的是什么? – 2013-04-05 11:25:49
@CharlesBrunet通过破碎,我的意思是代码不能正常工作。发生的事情是它返回“成功”时返回“无限循环”。 – Dan 2013-04-05 11:29:10