Largest palindrome not exceeding N which can be expressed as product of two 3 | Function to find the largest palindrome not exceeding N which can be expressed as the product of two 3 - digit numbers ; Stores all palindromes ; Stores the product ; Check if X is palindrome ; Check n is less than N ; If true , append it in the list ; Print the largest palindrome ; Driver Code ; Function Call
def palindrome_prod ( N ) : NEW_LINE INDENT palindrome_list = [ ] NEW_LINE for i in range ( 101 , 1000 ) : NEW_LINE INDENT for j in range ( 121 , 1000 , ( 1 if i % 11 == 0 else 11 ) ) : NEW_LINE INDENT n = i * j NEW_LINE x = str ( n ) NEW_LINE if x == x [ : : - 1 ] : NEW_LINE INDENT if n < N : NEW_LINE INDENT palindrome_list . append ( i * j ) NEW_LINE DEDENT DEDENT DEDENT DEDENT print ( max ( palindrome_list ) ) NEW_LINE DEDENT N = 101110 NEW_LINE palindrome_prod ( N ) NEW_LINE