Python program:
def checkBoard ( board ) :
    for i in range ( 8 ) :
        for j in range ( 8 ) :
            if board [ i ] [ j ] == ' k ' :
                if lookForn ( board , ' N ' , i , j ) :
                    return 1
                if lookForp ( board , ' P ' , i , j ) :
                    return 1
                if lookForr ( board , ' R ' , i , j ) :
                    return 1
                if lookForb ( board , ' B ' , i , j ) :
                    return 1
                if lookForq ( board , ' Q ' , i , j ) :
                    return 1
                if lookFork ( board , ' K ' , i , j ) :
                    return 1
            if board [ i ] [ j ] == ' K ' :
                if lookForn ( board , ' n ' , i , j ) :
                    return 2
                if lookForp ( board , ' p ' , i , j ) :
                    return 2
                if lookForr ( board , ' r ' , i , j ) :
                    return 2
                if lookForb ( board , ' b ' , i , j ) :
                    return 2
                if lookForq ( board , ' q ' , i , j ) :
                    return 2
                if lookFork ( board , ' k ' , i , j ) :
                    return 2
    return 1
def lookFork ( board , c , i , j ) :
    x = [ - 1 , - 1 , - 1 , 0 , 0 , 1 , 1 , 1 ]
    y = [ - 1 , 0 , 1 , - 1 , 1 , - 1 , 0 , 1 ]
    for k in range ( 8 ) :
        m = i + x [ k ]
        n = j + y [ k ]
        if inBounds ( m , n ) and board [ m ] [ n ] == c :
            return True
    return False
def lookForq ( board , c , i , j ) :
    if lookForb ( board , c , i , j ) or lookForr ( board , c , i , j ) :
        return True
    return False
def lookForb ( board , c , i , j ) :
    k = 0
    while inBounds ( i + + + k , j + k ) :
        if board [ i + k ] [ j + k ] == c :
            return True
        if board [ i + k ] [ j + k ] != ' - ' :
            break
    k = 0
    while inBounds ( i + + + k , j - k ) :
        if board [ i + k ] [ j - k ] == c :
            return True
        if board [ i + k ] [ j - k ] != ' - ' :
            break
    k = 0
    while inBounds ( i - + + k , j + k ) :
        if board [ i - k ] [ j + k ] == c :
            return True
        if board [ i - k ] [ j + k ] != ' - ' :
            break
    k = 0
    while inBounds ( i - + + k , j - k ) :
        if board [ i - k ] [ j - k ] == c :
            return True
        if board [ i - k ] [ j - k ] != ' - ' :
            break
    return False
def lookForr ( board , c , i , j ) :
    k = 0
    while inBounds ( i + + + k , j ) :
        if board [ i + k ] [ j ] == c :
            return True
        if board [ i + k ] [ j ] != ' - ' :
            break
    k = 0
    while inBounds ( i + - - k , j ) :
        if board [ i + k ] [ j ] == c :
            return True
        if board [ i + k ] [ j ] != ' - ' :
            break
    k = 0
    while inBounds ( i , j + + + k ) :
        if board [ i ] [ j + k ] == c :
            return True
        if board [ i ] [ j + k ] != ' - ' :
            break
    k = 0
    while inBounds ( i , j + - - k ) :
        if board [ i ] [ j + k ] == c :
            return True
        if board [ i ] [ j + k ] != ' - ' :
            break
    return False
def lookForn ( board , c , i , j ) :
    x = [ 2 , 2 , - 2 , - 2 , 1 , 1 , - 1 , - 1 ]
    y = [ 1 , - 1 , 1 , - 1 , 2 , - 2 , 2 , - 2 ]
    for k in range ( 8 ) :
        m = i + x [ k ]
        n = j + y [ k ]
        if inBounds ( m , n ) and board [ m ] [ n ] == c :
            return True
    return False
def lookForp ( board , c , i , j ) :
    if ord ( c ) >= 65 and ord ( c ) <= 90 :
        lookFor = ' P '
        if inBounds ( i + 1 , j - 1 ) and board [ i + 1 ] [ j - 1 ] == lookFor :
            return True
        if inBounds ( i + 1 , j + 1 ) and board [ i + 1 ] [ j + 1 ] == lookFor :
            return True
    else :
        lookFor = ' p '
        if inBounds ( i - 1 , j - 1 ) and board [ i - 1 ] [ j - 1 ] == lookFor :
            return True
        if inBounds ( i - 1 , j + 1 ) and board [ i - 1 ] [ j + 1 ] == lookFor :
            return True
    return False
def inBounds ( i , j ) :
    return i >= 0 and i < 8 and j >= 0 and j < 8
board = [ [ ' - ' , ' - ' , ' - ' , ' k ' , ' - ' , ' - ' , ' - ' , ' - ' ] , [ ' p ' , ' p ' , ' p ' , ' - ' , ' p ' , ' p ' , ' p ' , ' p ' ] , [ ' - ' , ' - ' , ' - ' , ' - ' , ' - ' , ' b ' , ' - ' , ' - ' ] , [ ' - ' , ' - ' , ' - ' , ' R ' , ' - ' , ' - ' , ' - ' , ' - ' ] , [ ' - ' , ' - ' , ' - ' , ' - ' , ' - ' , ' - ' , ' - ' , ' - ' ] , [ ' - ' , ' - ' , ' - ' , ' - ' , ' - ' , ' - ' , ' - ' , ' - ' ] , [ ' P ' , ' - ' , ' P ' , ' P ' , ' P ' , ' P ' , ' P ' , ' P ' ] , [ ' K ' , ' - ' , ' - ' , ' - ' , ' - ' , ' - ' , ' - ' , ' - ' ] ]
if checkBoard ( board ) == 0 :
    print ( " No ▁ king ▁ in ▁ danger " )
elif checkBoard ( board ) == 1 :
    print ( " White ▁ king ▁ in ▁ danger " )
else :
    print ( " Black ▁ king ▁ in ▁ danger " )

Index/key variables: i, j, k, m, n
Iterator variables: i, j, k