Q. Write a function that takes a number and tests if it is a prime number using recursion technique.
You can understand by Watching video :-
Answer :-
count = 0 def prime(num,n) : if n == num : return num else : global count if num % n == 0 : count += 1 prime(num , n+1) num = int(input("Enter a number : ")) prime( num , 2 ) if count > 0 : print(num, "is not prime number") else : print(num , "is Prime number ")
Output :-
Enter a number : 8
8 is not prime number
>>>
Enter a number : 2
2 is Prime number
>>>
Enter a number : 97
97 is Prime number
>>>
Enter a number : 101
101 is Prime number
>>>
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )