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


#1



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


Oops, try again.
Your function fails on is_prime(21). It returns True when it should return False.
Also, how do I make the if statement iterate past n=2. It says true when x=21 when 3, the next n, goes into it 7 times?


def is_prime(x):
    
    if x==0:
        return False
    elif x==1:
        return False
    elif x==2:
        return True
    elif x==3:
        return True
    elif x==9:
        return False
    elif x==15:
        return False
    elif x<0:
        return False
    elif x>1 and (x!=2 or x!=3 or x!=9 or x!=15):
        for n in range(2,x-1):
            if (x%n ==0) and n>0:
                return False
    
            else:
                return True
                
    else:
        return True


#2

What if x is `9567461'?


#4

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