Program to print characters present at prime indexes in a given string | Python3 program to print Characters at Prime index in a given String ; Corner case ; Check from 2 to n - 1 ; Function to print character at prime index ; Loop to check if index prime or not ; Driver Code
def isPrime ( n ) : NEW_LINE INDENT if n <= 1 : NEW_LINE INDENT return False NEW_LINE DEDENT for i in range ( 2 , n ) : NEW_LINE INDENT if n % i == 0 : NEW_LINE INDENT return False ; NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT def prime_index ( input ) : NEW_LINE INDENT p = list ( input ) NEW_LINE s = " " NEW_LINE for i in range ( 2 , len ( p ) + 1 ) : NEW_LINE INDENT if isPrime ( i ) : NEW_LINE INDENT s = s + input [ i - 1 ] NEW_LINE DEDENT DEDENT print ( s ) NEW_LINE DEDENT input = " GeeksforGeeks " NEW_LINE prime_index ( input ) NEW_LINE