human
Weakly Prime Numbers | function to check if N is prime.
Corner cases.
This is checked so that we can skip middle five numbers in below loop.
function to check if n is a weakly prime Number.
number should be prime.
converting N to string.
loop to change digit at every character one by one ..
loop to store every digit one by one at index j.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to weakly Prime Numbers and the other steps required.
 def isPrime ( n ) :
	if ( n <= 1 ) :
		return False
	if ( n <= 3 ) :
		return True
	if ( n % 2 == 0 or n % 3 == 0 ) :
		return False
	for i in range ( 5 , int ( n ** 0.5 ) + 1 , 6 ) :
		if ( n % i == 0 or n % ( i + 2 ) == 0 ) :
			return False
	return True
def isWeaklyPrimeNum ( N ) :
	if ( isPrime ( N ) == False ) :
		return False
	s = str ( N )
	for j in range ( len ( s ) ) :
		str1 = s
		for i in range ( 10 ) :
			c = str ( i )
			str1 = str1 [ : j ] + c + str1 [ j + 1 : ]
			Num = int ( str1 )
			if ( str1 [ j ] != s [ j ] and isPrime ( Num ) ) :
				return False
	return True
n = 294001
if ( isWeaklyPrimeNum ( n ) ) :
	print ( " Yes " )
else :
	print ( " No " )