Is_prime: why am I wrong?


#1


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

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
                break
        return True
   
            
is_prime(9)


#2

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


#3

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