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 because 6 can be written as a product, 2 × 3. My task is to use while loops in python to find if a number is prime or not.

For a given number I started checking if is divisible only by 1 and itself.

Here is my first solution:

x = 35
i = 2
is_prime = True
while i < x:
if x % i == 0:
is_prime = False
i = i + 1
if is_prime == True:
print(f'{x} is a prime number!')
print(f'{x} is not a prime number.')

In the next blogs, I will provide a faster version.