正如標題所示,我目前正在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