Is_prime: why am I wrong?


<Below this line, add a link to the EXACT exercise that you are stuck

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

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


With respect to your code..
Add one conditional statement (if) that checks if numbers are less than or equal to 1 then return False.


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