 # For Loops: How To Tell if a Number is Prime or Not in Python

So far, I have only used while loops to determine if a number is prime or not. For today, I am going to explain to you how you can use for loop to tell if a number is prime or not.

To understand the code below, you first need to…

--

--

# The Faster Version — How To Tell if a Number is Prime or not in python

In my last blog, I showed you the slower version of how to tell if a number is prime or not. Last time, I promised you that I’d show you the faster version in my next blog.

So, here it is:

`x = 17i = 0length = len(the_primes)the_primes = [2,3,5,7,11,13]is_prime = Truewhile i < length:    if x % the_primes[i] == 0:        is_prime = False        break    i = i + 1if is_prime == True:    print((f'{x} is a prime number!')) else:    print((f'{x} is not a prime number'))`

Input: x = 17

Output: 17 is a prime number!

I found out that you really don’t have to divide it by all the numbers before the number. You only have to divide it by the prime numbers before it.

--

--

# Prime Numbers

A prime number is a number greater than 1 that is not a product of two smaller natural numbers. For example, 3 is prime because the only ways of writing it as a product, 1 × 3 or 3 × 1, involve 3 itself. But 6 isn’t a prime number…

--

--