Is_prime


#1

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

Code :

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

Please help!


#2

you seem to have gotten this condition wrong:

if x > 2:

values lesser then 2 can’t be prime numbers, x > 2 will check for numbers larger then 2


#3

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