
/userfiles/images/prime_for_loop.png)

Here, to find a prime number we will use: Note: We start dividing it from 2 because every number can be divided by 1.

If the number 13 is divisible by any number between 2 to 12, then it's not a prime number. For example, if the number is 13, we will start from 13/2, 13/3, 13/4, and so on until 13/12. If yes, then we will divide the number between the range 2 upto the number itself.First, we will check if the number is greater than one (1) or not.To find a prime number, we have to follow these steps: Example: 13/1 = 13 and 13/13 = 1, so it is a prime number since it have only two factors 1, 13 How to find a prime number? One will be 1 and the other will be the number itself. What is a Prime Number?Ī prime number is a positive number that is greater than 1 and cannot be divided by any positive number except 1 and by itself.Įxamples of prime numbers are, 2, 3, 5, 7, 11 etc.Ī prime number can have only two factors. In this article, we will learn how to take a number as user input and check if the number is a prime number or not using for loop and while loop in Python.īefore starting, let's learn a bit about prime numbers.
