Is_prime - Help with testing if 9 is a prime number


"Your function fails on is_prime(9). It returns True when it should return False."

I expect the code to return false instead of true, and I am not clear why?

def is_prime(x):

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


You don't need break.


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