# Is_Prime. My code wont work

#1

I am stuck on 6/15. The is_prime lesson

The code below is what i put in. In my head it makes sense, but it always fails. It says it returns None instead of True on is_prime(3)

I don't necessarily want the answer. I just want to know what I am doing wrong.

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

#2

I just managed to get it all the way to 9 before it failed.

Now it makes it past 3 but fails at 9 saying it returned true when it should return false
heres the updated code

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

#3

Does this look correct?

#4

thank you, I noticed that when I was reviewing my code again. I was having trouble understanding why that wasn't correct. But then i figured it out.

Thanks again!

#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.