Python Program to Check Prime Number – Programming Code Examples

Python Program to Check Prime Number1 min read

In this python program, we will find whether a number is prime or not. Here we will use the if-else statement once again and the new thing we are going to use is for loop.

Here we take the modulus(%) of the given number(num variable) with every number(i variable) less than the num. And if the remainder shows 0 i.e the variable num is divided by the variable i without leaving any remainder then the variable i is the factor of the variable num and hence it prints the variable num is not a prime number and then breaks from the for loop because there is no need to check for other numbers(variable i). And if none of the numbers between the range is the factor of the variable num then it is a prime number.

Write a program to Check Prime Number in Python


Leave a Comment