Is_prime help


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

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


A function ends the moment a return keyword is reached, if a return keyword is reached in a loop simply breaks. (so you don't need the break keyword)

anyway, a number (in your case stored in variable x) is only a prime number if its not divisible by any number in range 2 (included) and x (excluded), thus you only want to return true after the for loop has finished running


You're awesome! ...............