15.6 is_prime Error-> "'bool' object is not callable" error


#1



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.


What's wrong with this code?


def est_premier(x):
    if(x<=2):
        return False
    else:
        for n in range(2,x):
            if x%n==0:
                return False
                break
        else:
            return True

print est_premier(0)


#2

break after return doesn't make sense, and for-else without break doesn't either. else after an if-statement that returns is just a way of adding indentation.

But that's all just extra code that does nothing.

What's truly wrong is the submission test, it's broken and there's no intention to fix anything in translated old tracks or old tracks in general really.


#3

Ty for your response. What can I do for continuing learning python and go over this exercice? is there a key code to pass this exercice over? because being stuck in this exercice with a working code isn't pleasant ^^.

If I have understood what you said, the instruction break make no sense. But I don't understand why the for-else loop doesn't either? because I test all number from 2 to x until I found a complete division with integer and if he don't found any "diviseur" this is a prime number? Can you explain me what is wrong? or how can I pass this exercice with working code ?

Thank you ! and sorry for my bad English (this is not my native tongue)


#4

for-else is affected by break, it does nothing special without it.

You can simply select next exercise, there's nothing preventing you from visiting exercises further ahead.

You can also crash the submission test which for no good reason makes it pass you:

# add the following after your own code
del est_premier
NameError = Exception = None

6. Is Prime
#5

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