6. is_prime



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

I can't figure this one out. I thought that x % n == 0 could handle is_prime(9). I was reading other people's questions about this exercise, and the moderators talked about how a function ends when a return keyword is reached. How can I fix mine so that this doesn't happen?

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
            elif x % n != 0:
                return True


Hey there! I think your question looks a lot like this topic:

And the second post there asnwers the question:

Good luck!


def anti_vowel(text):
k = []
s = ""
for i in range(0,len(text),1):
if text[i] == "a" or text[i] == "A" or text[i] == "e" or text[i] == "E" or text[i] == "i" or text[i] == "I" or text[i] == "o" or text[i] == "O" or text[i] == "u" or text[i] == "U":

s = "".join(k)
return s

this is the pimpliest way to understand and to do this


We're not supposed to give the answer, @kathan420. Especially not if it is wrong...


i won't give next time


Okay, I figured it out. Thanks for the help!


hi , this is may code and it's working.

def is_prime(x):
    p = 2
    if x == 0 or x == 1:
        return False  
    elif x < 0:
            return False    
    while p <= x:
        if x > p and x % p == 0:
            return False
        elif p == x:
            return True
        p += 1
print is_prime(-10)