这是我的代码,我不知道如何解决它......
def count_neighbours(grid, row, col):
neighbor_rule = ((-1, -1), (-1, 0), (-1, 1), (0, -1),
(0, 1), (1, -1), (1, 0), (1, 1))
chip = 0
for each_loc in neighbor_rule:
n_row = row + each_loc[0]
n_col = col + each_loc[1]
if 0 <= n_row < len(gird) and 0 <= n_col < len(gird[0]):
if gird[n_row][n_col] == 1:
chip += 1
else:
continue
return chip