Find next palindrome prime | Python3 program to find next palindromic prime for a given number . ; if ( 8 <= N <= 11 ) return 11 ; generate odd length palindrome number which will cover given constraint . ; if y >= N and it is a prime number then return it . ; Driver code
import math as mt NEW_LINE def isPrime ( num ) : NEW_LINE INDENT if ( num < 2 or num % 2 == 0 ) : NEW_LINE INDENT return num == 2 NEW_LINE DEDENT for i in range ( 3 , mt . ceil ( mt . sqrt ( num + 1 ) ) ) : NEW_LINE INDENT if ( num % i == 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT def primePalindrome ( N ) : NEW_LINE INDENT if ( 8 <= N and N <= 11 ) : NEW_LINE INDENT return 11 NEW_LINE DEDENT for x in range ( 1 , 100000 ) : NEW_LINE INDENT s = str ( x ) NEW_LINE d = s [ : : - 1 ] NEW_LINE y = int ( s + d [ 1 : ] ) NEW_LINE if ( y >= N and isPrime ( y ) ) : NEW_LINE INDENT return y NEW_LINE DEDENT DEDENT DEDENT print ( primePalindrome ( 112 ) ) NEW_LINE