2015-11-02 34 views
0

這是定義手數我需要幫助切片的益智遊戲

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 

回答

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是n沒有任何這些。我從你在這裏實際提供的最好的猜測..