Is_prime


#1



Can somebody please explain what is wrong with my code? I still have problems with indendation.
It throws the following error message:

"Your function fails on is_prime(-10). It returns None when it should return False."

Thank you in advance!


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


#2

this if condition:

if x == 0 or x == 1:

why not change it to lesser then 2? since then you catch 0,1 and all negative numbers (negative numbers can't be prime numbers)


#3

THANKS A LOT!!!! :smile: :thumbsup:


#4