Is_prime, can't figure out what's wrong. HELP!


Practise Makes Perfect - is_prime

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

Replace this line with your code. 
def is_prime(x):
    if x == 2:
        return True
    elif x < 2:
        return False
    elif x > 3:
        for n in range(2, x-1):
            if type(x % n) == 0:
                return False
                return False


lets say x is 3, we have this for the loop:

for n in range(2,3-1):

hm.. no steps to be done. Condition is met, you might want to scrap the -1

Also, a function ends the moment a return keyword which in your case happens in the first run of the loop, you might want to change the indent so that return True only happens when the loop finished running (and then return True, not False)


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