Python program to check whether a given number is prime or not – DzTechno


Python program to check whether a given number is prime or not

A positive integer greater than 1 is called a prime number if it is divisible by one and number itself except 1.

Example: 2,3, 7, 11, 13, 17, 19 are prime numbers, while 6 is not a prime number.

Source Code

The following is a source code to check whether the number is prime or not:

Output

Here is the result:

Case 1:

Case 2:

Explanation: In this program, we will check the number stored in a variable number is prime or not. The prime number is always greater than 1. So we will proceed only if the number is greater than 1.

The loops will be iterated from 2 to number -1. We will check if the number is completely divisible by any number from 2 to number -1. If there exists any factor, then it is not prime. Else the number is prime.


Leave a Reply

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