Is_prime


#1

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

I must be really overlooking something - I can't figure out why I'm getting this error, and it seems like I've tried many variations of my code.

I'm getting the error: "Your function fails on is_prime(3). It returns None when it should return True."

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

#3

a function ends the moment a return keyword is reached, if a return keyword is reached in a loop, the loop simply breaks

You only want to return True after the for loop has finished running


#4

That helped! Thank you


#5