Is_prime --> keep getting the same error message


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

I have been trying for an hour now... no idea why this doesn't work. :frowning: any help?

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


for x to be a prime number, x should shouldn't divisble by n over the entire range

so, we only want to return True after the for loop has finished running, currently your function will return True or False for the first n in range (return keyword will end the function)


Thanks Sir! :smiley:


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