Is_prime - is_prime(3) returns None when it should return True


#1

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

I keep getting the message "Oops, try again. Your function fails on is_prime(3). It returns None when it should return True. " & every previous solutions are not working.
Can someo

Summary

This text will be hidden

ne help me please help me understand the problem. Thanks


#2

It's difficult to read your code without indentations. Post your using ` before and after the code:

code

Cutting and pasting doesn't always work.

It may be easier to rearrange your conditionals in this order:

if x < 2 
    do something
elif x == 2 
    do something
else 
    execute your for loop

#3

Sorry I meant to say that you need three ticks before and after your code block in order to preserve your indentations.


#4


#6