Is_prime


#1



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


ERROR: Oops, try again. Your function fails on is_prime(9). It returns True when it should return False.


I don't understand why this error occurs? Can someone please help? Thanks!

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


Is_prime
#2

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

In your loop, return is reached in the first iteration (either return true or return false) so the loop ends in the first iteration, is this the desired behavior? If not, how do you think you can change this?


#4