Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())

board = []

for i in range(h):
    line = input()
    board.append(line)

new_board = []

for y in range(h):
    temp_text = ''
    if y == 0:
        for x in range(w):
            if board[y][x] == '#':
                temp_text = temp_text + '#'

            else:
                if x == 0:
                    check_text = board[y][x:x+2] + board[y+1][x:x+2]
                    bomb_count = check_text.count('#')
                    temp_text = temp_text + str(bomb_count)

                elif x == w-1:
                    check_text = board[y][x-1:x+1] + board[y+1][x-1:x+1]
                    bomb_count = check_text.count('#')
                    temp_text = temp_text + str(bomb_count)

                else:
                    check_text = board[y][x-1:x+2] + board[y+1][x-1:x+2]
                    bomb_count = check_text.count('#')
                    temp_text = temp_text + str(bomb_count)

    elif y == h-1:
        for x in range(len(board[y])):
            if board[y][x] == '#':
                temp_text = temp_text + '#'

            else:
                if x == 0:
                    check_text = board[y-1][x:x+2] + board[y][x:x+2]
                    bomb_count = check_text.count('#')
                    temp_text = temp_text + str(bomb_count)

                elif x == w - 1:
                    check_text = board[y-1][x-1:x+1] + board[y][x-1:x+1]
                    bomb_count = check_text.count('#')
                    temp_text = temp_text + str(bomb_count)

                else:
                    check_text = board[y-1][x-1:x+2] + board[y][x-1:x+2]
                    bomb_count = check_text.count('#')
                    temp_text = temp_text + str(bomb_count)

    else:
        for x in range(len(board[y])):
            if board[y][x] == '#':
                temp_text = temp_text + '#'

            else:
                if x == 0:
                    check_text = board[y-1][x:x+2] + board[y][x:x+2] + board[y+1][x:x+2]
                    bomb_count = check_text.count('#')
                    temp_text = temp_text + str(bomb_count)

                elif x == w - 1:
                    check_text = board[y-1][x-1:x+1] + board[y][x-1:x+1] + board[y+1][x-1:x+1]
                    bomb_count = check_text.count('#')
                    temp_text = temp_text + str(bomb_count)

                else:
                    check_text = board[y-1][x-1:x+2] + board[y][x-1:x+2] + board[y+1][x-1:x+2]
                    bomb_count = check_text.count('#')
                    temp_text = temp_text + str(bomb_count)

    new_board.append(temp_text)

for text in new_board:
    print(text)


Fixed submission:
h, w = map(int, input().split())

board = ['.'*(w+2)]

for i in range(h):
    line = input()
    board.append('.' + line + '.')
board.append('.'*(w+2))

new_board = []

for y in range(1,h+1):
    temp_text = ''

    for x in range(1, w+1):
        if board[y][x] == '#':
            temp_text = temp_text + '#'

        else:
            check_text = board[y-1][x-1:x+2] + board[y][x-1:x+2] + board[y+1][x-1:x+2]
            bomb_count = check_text.count('#')
            temp_text = temp_text + str(bomb_count)

    new_board.append(temp_text)

for text in new_board:
    print(text)