Python Program to Check Prime Number
We will write a program here in which we will check that a given number is a prime number or not.
If the natural number is greater than 1 and having no positive divisors other than 1 and the number itself etc.
For example: 3, 7, 11 etc are prime numbers.
Other natural numbers that are not prime numbers are called composite numbers.
For example: 4, 6, 9 etc. are composite numbers.
Let us look at the following example to understand the implementation.
Enter an input number:17 17 is a prime number
We have used nested if else condition to check if the number is a prime number or not.
First, we have checked if the given number is greater than 1 or not. If it is not greater than 1, then the number will directly come to the else part and print 'not a prime number.'
Now, the number will enter into for loop where we perform Iteration from 2 to number/2. Then, we used nested if else condition inside the for loop. If the number is completely divisible by 'i' then, it is not a prime number; else, the number is a prime number.