Probleme avec est_premier


#1



MERCI de votre aide....

https://www.codecademy.com/fr/courses/python-intermediate-fr-FR-py0yl/0/6?curriculum_id=5370f030fed2a866a2000001

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
    else:
        for n in range (2, x-1):
            if x % n == 0:
                return False
            else: 
                return True


#2

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.


#3

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


#4

with credits to nicoekkart, there is a workaround:

def est_premier(n):
    return est_premier