Is_prime not working? [solved]


the weirdest thing is that it gives me the same error if i make it == to return False
if i make the range 2 to x-1, it errors out at is_prime(3) saying that it "returns None when it should return True"

inb4 the mod says that i shouldnt have an else in my loop.

Replace this line with your code.


jk i figured it out. gotta pull the else out of the loop. if anyone can explain why it shouldnt be in line with the loop, i'd love an explaination


I think it is because the else is for the if's not inside the loop


It's not perfect but....

def is_prime(x):
count = 0
for i in range(1, (x+1)):
if x % i == 0:
count += 1
if count > 2 or x <= 0 or x == 1:
return False
return True


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