# Python Program To Check Whether The Number Is Prime Or Non-Prime

Robort | April 11, 2020, 11:47 p.m.

A prime number is a positive whole number greater than 1 which is divisible by 1 and itself are called Prime Numbers. 2, 3, 5, 7, 11, 13 are the first few prime numbers.

**For Example **— 3 is only divisible by itself.

**Some interesting facts about Prime numbers -**

**1**.0 and 1 are not considered as prime numbers.

2. Numbers that have more than two factors are called composite numbers.

**For Example **— 4 which is (2*2) it is divisible by 2 so it is not a prime number.

**3. **2 is the only even prime number.

**4. **Any number which is greater than 5 and it ends with 5 and it is divisible by 5, These numbers are Considered as a Non-Prime Number.

In this post, we will create a Python program to check whether the given number is Prime Number or Non-Prime number.

# Algorithm To Finding Number Is Prime Or Non-Prime:

**Step 1**: Take the input from the User.

**Step 2**: Check whether the number is greater than 1 or not if the number is less than 1 than it is Non-Prime.

**Step 3**: Check if the number gets evenly divided by any number from 2 to half of the number ( It Optimised the algorithms & Searching).

**Step 4**: Print the output.

Here we have optimized the algorithm to search only till half of the given number which significantly improves the performance for very large numbers.

# Now Write the Python Program To Check Whether The Number Is Prime Or Non-Prime:

**# Taking the input from User number = int(input("Enter The Number")) if number > 1: for i in range(2,int(number/2)): if (number % i == 0): print(number, "is Non-Prime Number") break else: print(number,"is a Prime number") # If the number is less than 1 it can't be Prime else: print(number,"is not a Prime number")**

# Explanation Of Program:

**Line 1:** In the first line, we will take the input from the user by input() keyword and converting it to an integer data type, If the user inputs a float number than we want to convert that number to an integer.

**Line 2: **Next, we are comparing if the number is less than 1 because only a number greater than 1 can be called a Prime number.

**Line 3: **Inside the loop, we are diving the number to every number between 2 and the half of the number if no factor is found the number is Prime gets printed out along with the number.

So run your program and check here.

**Enter The Number 1 1 is not a Prime number.**

**Enter The Number 2 2 is a Prime number**

**Enter The Number 598622 598622 is not a Prime Number**

**Enter The Number -10-10 is not a Prime number**

*Originally published at** **http://www.bloggystacker.com**.*