Python program to check prime number

Python program to check prime number

Python program to check prime number

In this example, we will learn how to check if a number is a prime number.

A Prime number is greater than 1 and should not be another factor except 1 and the number itself. 

This means any number which can not be divisible by any other number except 1 and itself will be called a Prime number.

#python program to check prime number

n=int(input(“Enter number to check prime : “))
flag=0
if(n == 0 or n == 1):
    flag = 1
   
for i in range (2,n):
    if (n % i == 0):
        flag = 1
        break
if(flag == 0):
    print(‘ {0} is a prime number.’.format(n))
else:
    print(‘ {0} is not a prime number.’.format(n))

Output

Enter number to check prime : 5
5 is a prime number. 

If you like my post please share it with your friends by simply clicking the below social media button, and Don’t forget to comment so we will update ourselves.

Share in a Single Click

Leave a Reply

Your email address will not be published. Required fields are marked *