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


#1


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
    else:
        for n in range(2,x):
            if x % n ==0:
                return False
                break
            else:
                return True


Is_prime returns true for 9 instead of false
#2

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


#3

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


#4

Thank you very much !!!! ^_^


#5

No problem! Happy coding! :smiley:


#6