运行我正在使用海龟图形绘制的程序,我输入了一个退出命令,但是现在每当我输入任何单字命令时,我都会在“返回”的 elif 处得到一个 indexerror(IndexError:list index out of range)命令:
def parse_line(line):
global items_in_line
items_in_line = line.split(" ",1)
if items_in_line[0] == "forward":
if isinstance(items_in_line[1], int):
return items_in_line
elif items_in_line[0] == "back" or "backward":
if isinstance(items_in_line[1], int):
return items_in_line
...
elif items_in_line[0] == "exit":
sys.exit()
line=input("Enter a turtle command or enter 'file' to load commands from a file")
x = parse_line(line)
为什么?我该如何解决这个问题?