Is_prime


#1

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

it is not working still
ERROR is:
Oops, try again. Your function fails on is_prime(-10). It returns True when it should return False.


is_prime-STUCK
#2

change your code as this:

3.     if x < 2:
4.         return False

#3

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