You have to remember that your for loop is producing a result every time it iterates, so in your code as soon as x%n is zero it returns True meaning itâ€™s a prime, in your code as soon as n = 2 on the first iteration the function returns true.

What you need to think about is using a for with an else statement, if the condition for x%n is never zero before the range runs out then it will go to the else statement and return True, you wonâ€™t need to add a break here as the function will return False before it goes onto the else statement. Hopefully this helps !

There are a few issues. Letâ€™s walk through them.

The range.

Look at your range. Hereâ€™s the instructions:

For each number n from 2 to x - 1, test if x is evenly divisible by n.

In the for loop, you want to check if the number is evenly divisible. And if no, return False. Think about that one. Look at your code. You are checking that itâ€™s not evenly divisible and then return True.

Returning too early.

for n in range(2,x):
if x % n != 0:
return True
else:
return False

Look at the else code block above. We want to loop through all of the numbers in that range. If the conditional expression if x % n == 0: is True, that means itâ€™s an even number. We want to stop the loop and return False.

But we want to loop through all of the numbers until:

thanks for your answer
i changed it a bit, but still not workingâ€¦

def is_prime(x):
if x > 2:
for n in range(2,x-1):
if x % n == 0:
return False
else:
return True
elif x < 2:
return False
elif x == 2:
return True```
gets the error Your function fails on is_prime(3). It returns None when it should return True.
i dont understand why .Its suppose to be in the first condition...

ok now i took out the - else: return True from the loop
it doesnt give an error anymore, it opened the next level but it doesnt say i was right. i think thats a bug alreadyâ€¦

def is_prime(x):
if x < 2:
return False
elif x == 2:
return True
else:
for n in range(2, x - 1):
if x % n == 0:
return False
# You made it this far.
# Look at the instructions.
# What should you return here.

If the checks made it to end of the loop and itâ€™s not an even number, what should you return?

yes. i changed it already and returned True outside the loop. now it just return nothing. Not an error but it also doesnt say its ok. it just open the option to move to the next part. i am not sure whats going onâ€¦;

for n in range(2, x-1):
if x % n == 0:
return False
# you return False here if the condition is true (if x % n == 0) #or else return True outside the loop
return True

â€śâ€ťâ€śbut what if the condition is met(if x % n == 0)
and because you put (return True) outside the loop
would (return True) still return that value or ignore it ? â€śâ€ťâ€ť

im just confuse on that part please tell me, thank you

I was only showing the loop portion of the solution. Hereâ€™s the remaining part of it.

def is_prime(x):
if x < 2:
return False
elif x == 2:
return True
for n in range(2, x - 1):
if x % n == 0:
return False
return True

The checks are:

Is it less than 2? If yes, then that number is not prime. Return False.

Is it equal to 2? If yes, then 2 is a prime. Return true.

If we made it this far, then we need to check the number set from 2 up to the number -1. Loop through each number to check if x % n == 0. If yes, then itâ€™s not prime; return False.

If we made through all of the checks, then itâ€™s a prime number. We can return True.