Python Program To Check Number Is Prime or Not

What is prime number ?

A prime number is a number which divides only by 1 or number itself.

Number is a prime number or not, we need to divide it successively by all numbers from 2 to one less than that number. if remainder value for any of these division is zero then that number is not a prime number.

Prime Number Python Program

This python program is used to identify whether a number is prime number or not.


def check_prime_number(num):
    index = 2;
    while (index <= num-1):
        if (num % index == 0):
            return False;
        index += 1;
    if (index == num ):
        return True;
    return False;

if __name__ == '__main__':
    num = int(input("Enter number: "));
    is_prime_number = check_prime_number(num);
    if is_prime_number:
        print("%d is a prime number!" % num);
        print("%d is not a prime number!" % num);
$ python
Enter number: 32
32 is not a prime number!
$ python
Enter number: 33
33 is not a prime number!
$ python
Enter number: 5
5 is a prime number!

Privacy Policy  |  Copyrightcopyright symbol2020 - All Rights Reserved.  |  Contact us   |  Report website issues in Github   |  Facebook page   |  Google+ page

Email Facebook Google LinkedIn Twitter