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


#1



https://www.codecademy.com/en/courses/python-intermediate-en-rCQKw/0/6?curriculum_id=4f89dab3d788890003000096


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


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


#2

There is no condition to test for 0, hence no return value. This is where None results. The test for less than 2 needs to be before the loop.


#3

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