Is Prime


#1

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

In this line, I keep getting 4 to come up True when it should be False. Help!!


#2

here:

elif x == 2 or 3:

if 3 equals what? currently it analyses if 3 is true, it doesn't compare 3 to anything.

also, if this is true:

elif x > 3:

then else will never run, since elif was true


#7

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