Is prime


#1

@stetim94 could you please help me? I get the same error message as @bitninja99561(Oops, try again. Your function fails on is_prime(3). It returns None when it should return True.)

Here is my code :

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

Is_prime
#2

A function ends the moment a return keyword is reached, if a return keyword is reached in a loop, the loop breaks

You only want to return True after the for loop has finished running


#3

Thank you so much, stetim94


#4