Probleme avec est_premier


MERCI de votre aide....

Oups, merci de réessayer. Votre fonction a échoué sur 0 comme entrée car votre fonction indique "'bool' object is not callable" error.

Remplace cette ligne avec ton code.
def est_premier(x):
    if x <= 1:
        return False
    elif x == 2 or x == 3:
        return True
        for n in range (2, x-1):
            if x % n == 0:
                return False
                return True


i just explained the problem here, here is the answer:

the biggest problem your code has, is that your for loop will run only once. In the first run of the for loop, either if is evaluated to true, otherwise else will run. Either way, a return keyword is reached in the first run of the loop, the moment a return keyword is reached, the function ends (including the loop inside the function)

put the else at the same indent level as your for loop. Then it should work, why? If the number is not a prime, if would be true at some point, false is returned, and the function ends. Otherwise, all values are looped, and True gets returned (which is good, since the number is not a prime.


There is also a problem in the checking script, so you can't pass it, try the english exercise


with credits to nicoekkart, there is a workaround:

def est_premier(n):
    return est_premier