Thanks for the reply I have edited my code but it is not working and i wish you can explain what you said a liitle bit

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

did you click the answer i posted above? It contains a detail explanation

a function ends the moment a return keyword is reached

if a return keyword is reached in a loop, the loop breaks so the function can end

so for x=9 (9 is not a prime number), the first number tested by the loop is 2. 9 % 2 == 0 is false. So else runs, return True causes your function to end. Is that what you want for x=9?

"Oops, try again. Your function fails on is_prime(3). It returns None when it should return True."

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

in range, why x-1? range doesn't includes its stop value, so no reason to subtract

Please tell me you read some of the things i posted above? Its also the answer to your problem. If you don't understand, let me know what of it, you don't understand

Let's think about it, for example, No for n=2, n=3... But when it comes to n=5, Yes. Now you should also finish searching (break) for n, along with return False.

If x is not divisible for all n variables, return True. Be careful. Is it if/else statement or for/else statement?(Is there any if/else statement in here?)

@stetim94 I tried your sol but still i gives error "Oops, try again. Your function fails on is_prime(9). It returns True when it should return False."

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

seriously? I explained two times in this topic why it fails for x=9, plus a more extensive explanation i linked to:

And so far, you have given no acknowledge you read it. Did you read it? Please show me your thought process so i can fill in any gaps, i can keep writing general explanations in slightly different wording, but i don't think that gets us anywhere

I know you are learning (like me) and I know how difficult it is to break away from the thought process of solving the problem in the way that you currently are, but I recommend coming at the problem in a different way. For example, you don't need to use a for loop with range() to solve this problem.

I just spent like 2 hours trying to solve the problem. It was frustrating sometimes but I managed to solve it with a while loop. The tip I can give that might save you some of my frustration is to check your indentations and make sure your returns are making sense in your code.

If you want some more tips or if you want to see my answer you can send me a reply!