这是定义移动号码的代码
def move(pos,empty,board):
m = pos[0]//
n = pos[1]
if empty == (m-1,n) or empty == (m+1,n)or empty == (m,n-1) or empty == (m,n+1):
board[empty[0]][empty[1]] = num
board[m][n] = 0
empty = (m,n)
else :
print('can\'t move! try again.')
结果:
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
sliding_puzzle()
File "C:\Users\sungod\Desktop\과제.py", line 57, in sliding_puzzle
(empty,board)=move(pos,empty,board)
File "C:\Users\sungod\Desktop\과제.py", line 35, in move
m = pos[0]
TypeError: 'NoneType' object is not subscriptable
答案 0 :(得分:1)
line 35, in move m = pos[0] TypeError: 'NoneType' object is not subscriptable
如果某个对象不可订阅,则它不具有以下任何形式:
string: "foobar"[3] == "b"
tuple: (1,2,3,4)[3] == 4
list: [1,2,3,4][3] == 4
dict: {"a":1, "b":2, "c":3}["c"] == 3
这意味着pos不是任何一个。我最好从你在这里提供的东西猜测..