Problem:
You are given an H × W grid.   The squares in the grid are described by H strings, S_1,...,S_H.   The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W).   `.` stands for an empty square, and `#` stands for a square containing a bomb.  Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square.   (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.)   He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square.  Print the strings after the process.

Incorrect submission (verdict: Wrong Answer):
import sys
def main():
    in1 = input()
    nums, length = in1.split(' ')
    nums= int(nums)
    length = int(length)
    bombs = []
    # print(nums)
    #
    for i in range(nums):

        bombs.append(input())
    print(bombs)




    checked = [['']*length for i in range(nums)]
    for i in range(nums):
        for j in range(length):
            if bombs[i][j] == '#':
                checked[i][j] = '#'
            else:
                bombnum = 0
                if i != 0:
                    if j != 0:
                        if bombs[i-1][j-1] == '#':
                            bombnum += 1

                    if j != length -1:
                        if bombs[i-1][j+1] == '#':
                            bombnum += 1

                    if bombs[i-1][j] == '#':
                        bombnum += 1


                if j != 0:
                    if bombs[i][j-1] == '#':
                        bombnum += 1

                if j != length-1:
                    if bombs[i][j+1] == '#':
                        bombnum += 1


                if i != nums-1:
                    if j != 0:
                        if bombs[i+1][j-1] == '#':
                            bombnum += 1

                    if j != length -1:
                        if bombs[i+1][j+1] == '#':
                            bombnum += 1

                    if bombs[i+1][j] == '#':
                        bombnum += 1

                checked[i][j] = bombnum
    for i in checked:
        for j in i:
            print(j, end = '')
        print('')

if __name__ == '__main__':
    main()

Fixed, accepted submission:
q=list(map(int,input().split()))
grid=[]
def ze(x,y):
  z=[]
  if y[0]+1<x[0]:
    z.append([y[0]+1,y[1]])
    if y[1]+1<x[1]:#
      z.append([y[0]+1,y[1]+1])
    if y[1]-1>=0:
      z.append([y[0]+1,y[1]-1])
  if y[0]-1>=0:
    z.append([y[0]-1,y[1]])
    if y[1]+1<x[1]:#
      z.append([y[0]-1,y[1]+1])
    if y[1]-1>=0:
      z.append([y[0]-1,y[1]-1])    
  if y[1]+1<x[1]:
    z.append([y[0],y[1]+1])
  if y[1]-1>=0:
    z.append([y[0],y[1]-1])
  return(z)
for i in range(q[0]):
    y=input()

    grid.append([i for i in y])
  
for i in range(q[0]):
    for j in range(q[1]):
        if grid[i][j]=='.':
            
          
            lamsa=ze(q,[i,j])
            
            count=0
            
            for k in range(len(lamsa)) :
                
                
                if grid[lamsa[k][0]][lamsa[k][1]] == '#' :
                  count+=1
            grid[i][j]=count      
                
for i in range(q[0]):
    pr=''
    for j in range(q[1]):
        pr=pr+str(grid[i][j])
    print(pr)