6/15 is_prime : Working Fine. But not for 9 as a Prime Number


This is my code , i don't know why return True when I print is_prime(9)

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

Is_prime returns true for 9 instead of false

I believe this will help you out! All credit to Factoradic as well I didn't come up with this answer.


Also this from Stetim94 might help as well. Once again all credit to Stetim94 I didn't come up with this answer.


Thank you very much !!!! ^_^


No problem! Happy coding! :smiley: