IS PRIME help


#1



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


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


Dont understend why 9 returns True


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


#2

lets see, for x=9, agree that the first iteration of the loop this is the if condition:

if 9 % 2 == 0

this condition is false, so else will run. Which returns True. Once a return keyword is reached, the function ends (the loop will break)

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


#3

got it, Thank You:)))))))))))))))))))))))))


#4