is_prime


#1


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

What is wrong? This is seriously getting annoying


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


#2

you need to check some exceptions (with if ... ) - what happens if you pass 0 or 1 into your function? They both should return False, do they?


#3

also, the range function goes from the first argument to the second argument but does not include the second argument - e.g. range(1,5) would return 1, 2, 3, 4

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