6. is_prime


#1




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


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


#2

@cnadler ,

else:
    return True

Only do this after the for loop has completed all its iterations without finding an n that divides x evenly. You need to remove a level of indentation from that else block for this to happen.


#3

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