I have a grid as a tuple of tuples with integers (1/0), a row number and column number for a cell as integers. And I have to find how many neighbouring cells have neighbours as an integer.
It's a task from the www.checkio.org, an interesting site of learning python.
Here is my code:
def count_neighbours(grid, row, col):
grid = ()
count = 0
for pos in ((row - 1, col), (row + 1, col), (row, col - 1), (row, col + 1), (row - 1, col - 1), (row - 1, col + 1), (row + 1, col - 1), (row + 1, col + 1)):
if pos == 1:
count += 1
return count
The system answers to me that there are no neighbours near the chosen cell. Please explain me what's wrong and thank you for attention!