Alternate Primes till N | Function for checking number is prime or not ; if flag = 0 then number is prime and return 1 otherwise return 0 ; Function for printing alternate prime number ; counter is initialize with 0 ; looping through 2 to n - 1 ; function calling along with if condition ; if counter is multiple of 2 then only print prime number ; Driver code ; Function calling
def prime ( num ) : NEW_LINE INDENT flag = 0 NEW_LINE for i in range ( 2 , num // 2 + 1 ) : NEW_LINE INDENT if num % i == 0 : NEW_LINE INDENT flag = 1 NEW_LINE break NEW_LINE DEDENT DEDENT if flag == 0 : NEW_LINE INDENT return 1 NEW_LINE DEDENT else : NEW_LINE INDENT return 0 NEW_LINE DEDENT DEDENT def print_alternate_prime ( n ) : NEW_LINE INDENT counter = 0 NEW_LINE for num in range ( 2 , n ) : NEW_LINE INDENT if prime ( num ) == 1 : NEW_LINE INDENT if counter % 2 == 0 : NEW_LINE INDENT print ( num , end = " ▁ " ) NEW_LINE DEDENT counter += 1 NEW_LINE DEDENT DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 15 NEW_LINE print ( " Following ▁ are ▁ the ▁ alternate ▁ prime " + " number ▁ smaller ▁ than ▁ or ▁ equal ▁ to " , n ) NEW_LINE print_alternate_prime ( n ) NEW_LINE DEDENT