How To Check Prime Number in Python Program

A number that is divisible only by itself and 1 (i.e. 2, 3, 5, 7, 11) is called Prime Number.

Note: 0 and 1 are not Prime Number

Python Program to Check Number is Prime Number or Not

To understand this example, you should have knowledge of following Python programming topics:

Source Code: Python Program to Check Prime Number

# A number that is divisible only by itself and 1 (i.e. 2, 3, 5, 7, 11) is called Prime Number
# 0 and 1 are not Prime Number

num =  int(input("Enter  a  number"))

if  num > 1 :
    for  i  in  range(2, num):
        if (num % i == 0 ):
            print(num,"  is  not  a  prime number") 
            break
    else:
        print(num,"is  a  prime  number")
else:
    print(num,"  is  not  a  prime  number")

It’s also available on GitHub: https://github.com/studygyaan/python-tutorial/blob/master/Python-Prime-Number.py