Prime Number Program in Python

Written by

Himani Kohli

In this program, we are going to check whether the given number is prime or not by using python.

Prime numbers are those number which are greater than 1 and whose factors are 1 and number itself.

Example-2,3,5,7 etc.


  1. Input a number from the user.
  2. Using for loop, we use the range from 2 to n/2
  3. If we find a factor in the above range then the number is not prime
  4. Else it is prime


n= int(input( "enter the number that has to be checked:"))
for i in range(2,int((n/2))):
    if(n%i ==0):  //finding whether the number has a factor or not
    print("it is not prime")
    print("it is prime ")


enter the number that has to be checked:97
it is prime

enter the number that has to be checked: 54 it is not prime