我有一项工作,要求我们创建一个点网格以及一个光标,当给出命令时,该光标在网格上上下,左右,左右移动。到目前为止,我的问题是,当我使用show_grid()函数时,我不断收到错误代码(未定义名称“ show_grid”)。这是我到目前为止所拥有的。
x = y = 0
size = int(input('Enter the size of the board: '))
print(f'Current location: ({x},{y})')
show_grid(x,y)
while True:
option = show_menu()
if option == 0:
print(f'Current location: ({x},{y})')
break
else:
x, y = move(x, y, option)
print(f'Current location: ({x},{y})')
if 0 <= x < size and 0 <= y < size:
show_grid(x,y)
else:
print('The new location is off the board.')
break
print('Exit the program')
看来可能是导入问题,或者您需要为show_grid(x,y)
定义方法。让我知道是否有帮助!