Prime number program in Python

In this post we shall learn about finding prime number program in python.If a number is only divisible by 1 and itself then that number is called as prime number.Otherwise it is not a prime number.

The following program is for finding prime number

n = int(input("\n		Enter number to find whether it is prime or not:"))
flag = 0
i = 0
for i in range(2,n-1) :
	if((n%i) == 0) :
		flag = flag +1
if(flag == 0) :
	print("\n\t\tGiven number " + str(n)+" is a prime number");
else :
	print("\n\t\tGiven number " + str(n) +" is not a prime number" );

prime number

Download the Source Code

About Anuroop D

Very enthusiastic about technology and likes to share my knowledge through blogging. Has Bachelor's in Information Technology and currently pursuing my PhD in Computer Science.
This entry was posted in Python and tagged , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s