
def retNumOrZero(values, row, column):
    if 0 > row or row >= len(values) or 0 > column or row >= len(values[0]):
        return None
    
    return values[row][column]

def neighborAverage(values, row, column):
    nums = [retNumOrZero(values, row - 1, column - 1), retNumOrZero(values, row - 1, column), retNumOrZero(values, row - 1, column + 1), retNumOrZero(values, row, column - 1), retNumOrZero(values, row, column), retNumOrZero(values, row, column + 1), retNumOrZero(values, row + 1, column - 1), retNumOrZero(values, row + 1, column), retNumOrZero(values, row + 1, column + 1)]
    su = 0
    d = 0
    for n in nums:
        if n is not None:
            su += n
            d += 1

    print(su / d, end="\t")

a = [[0,1,2],[3,4,5],[6,7,8]]

neighborAverage(a, 0, 0)