我需要帮助的切片拼图游戏

2024-04-19 21:36:14 发布

您现在位置:Python中文网/ 问答频道 /正文

这是定义移动编号的代码

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

Tags: orinpyposboardmove定义line
1条回答
网友
1楼 · 发布于 2024-04-19 21:36:14
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不是这些。我从你提供的资料中猜到的。。你知道吗

相关问题 更多 >