Python Program to check Prime Number

0
197
Python Program to check Prime Number

In this program, we will be creating a Python Program to Check Prime Number whether a given is Prime or not. For this program, we will take a number from the user that he wants to check for prime.

We will be making a loop and will divide that number with all the numbers less than that number except 1. If any number divides it completely without leaving a remainder then it is not a prime number and if it does not get divided by any number then it is a prime number.

Hope this program will help you to check if the number is Prime or not.

Python Program to Check Prime Number Code

n= int(input("Enter a number"))
for x in range(2,n):
    if n%x==0:
        break
if x+1==n:
    print (n,"is a prime number")
else:
    print (n,"is not a prime number")

Output

Enter a number571
571 is a prime number
Enter a number267
267 is not a prime number

If you any doubt feel free to ask me in social media

Also, Read

Python Program to Remove Empty Strings from a List

Python program will print 1 to 10 numbers using while loop

Python program to print odd numbers between 1 to 10 using while loop.

LEAVE A REPLY

Please enter your comment!
Please enter your name here