Is_prime


#1



Is_prime


"Oops, try again. Your function fail when is_prime(-7). It returns True when should returns False."


But -7 should be prime, it's 7! So wtf.
I'm thinking in put a "abs(x)" somewhere...


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


#2

i would replace this line:

if x == 0 or x == 1:

to check for values lesser then 2, this way you covered all negative numbers which are all not prime numbers


#3

It worked! Thank you man :smiley:


#4