Program of Prime number by recursion in python

Objective of this Post- Program of Prime number by recursion in python. Write a recursive function ChkPrime() that checks a number for Prime. This python project is useful for beginners and CBSE KV School Class 11 and Class 12 students computer science practical file and NIELIT O Level Programming and Problem Solving through Python ( Module M3-R5).

Program code screenshot

The source code of python program to generate prime number by recursion is given below. The source code file of this program is present in the last column on this page.

Explanation of Python Code

def ChkPrime(n,i): #function for checking prime number ChkPrime(n,i) n is the number to be found whether it is prime or not. i is the number #from where divisibilty starts
while i<n: #while loop goes on till i<n i is increased by 1 every time
if n%i==0: #if n is divisible by i then it will return false
return False #Returing false
else:
i+=1 # i is increased by one
ChkPrime(n,i) # recursive function
return True #return true if it find indivisible by i
n=int(input(“Enter the number”)) # main program takes integer n as input
if ChkPrime(n,2): # call the recursive function with i=2 value
print(“Number is prime”) # if the function return true number is prime
else:
print(“Number ain’t prime”) #if the function return false

Output of Program of Prime number by recursion in python

Testing of Program

53 is input, to check whether it is prime or not. Its shows 53 as prime. which is correct.
we also have given input as 22 which we know it is not prime , it shows the same.

Source code of Program -> click here

Thanks for reading and learning about this program.

for more python programs -> click here

Hello World Program in Python

Input a welcome message and display it in Python

Display the larger / smaller number in Python.

Greatest of Three Numbers in Python using Nested if

Patterns using nested loop in Python

Program to Print Pattern in Python

Program to input the value of x and n and sum of series in Python

Python Program for Armstrong, Prefect Number, Palindrome

Program of Prime number by recursion in python

Prime Number Program in Python

Write a Program to Print Fibonacci Series in Python

LCM and GCD program in Python

Python program to count number of vowels in a string

Whether a String is Palindrome or not in Python

Bubble Sort Program in Python

Linear search in python using list

Program to read a text file in python

Python program to read a file line by line

Program to Count Vowels and Consonants in Python

Stack Program in Python

Queue Program in Python

Python Leap Year Program for Beginners

Python Program to Print Series and Addition

Binary Search Program in Python

Program to find sum of digits in python

Sum of numbers divisible by 3 and 5 in python

error: Content is protected !!