Is_prime - Help with testing if 9 is a prime number


#1



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


"Your function fails on is_prime(9). It returns True when it should return False."


I expect the code to return false instead of true, and I am not clear why?


def is_prime(x):

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


#2

You don't need break.


#3

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