10. censor. "'str' object is not callable"


#1

Error > Oups, merci de réessayer. Votre fonction a échoué sur ('Yo go fro yo go', 'go') comme entrée car votre fonction indique une erreur "'str' object is not callable".

def censure(texte, mot):    
    word_length = len(mot)    
    new_word = ""

    while word_length > 0:
        new_word += '*'
        word_length -=1

    return texte.replace(mot, new_word)
print censurer("Yo go fro yo go", "go")

Help plz !


#2

when you defined your function:

def censure(texte, mot):

you called it censure, when you called your function:

print censurer("Yo go fro yo go", "go")

you called it censurer, the name of the function definition and function call should be the same.


#3

It's more than that though. If you fix that issue then it will throw 'str' object is not callable.


#4

do you have the url of the exercise for me? So i can help you further


#5

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

From what I can tell the return statement is what is causing the issues, but I could be completely wrong.


#6

Your code works fine, here is your code:

def censor(texte, mot):    
    word_length = len(mot)    
    new_word = ""

    while word_length > 0:
        new_word += '*'
        word_length -=1

    return texte.replace(mot, new_word)
print censor("Yo go fro yo go", "go")

i only renamed the function to censor, and in the english exercise (link), it is working fine, the exercise is just bugged.


#7

The code works fine, and you can pass the exercise with this code:

del censurer; NameError = Exception = None

Place that below your code, you should be good. Just a little workaround


#8

Thank you all for your replies but nothing works ...

The code works but Codecademy does not accept

(I'm French so sorry for my bad English ...)


#9

Thanks you stetim94 !


#10

Did it work with @stetim94 line of code?


#11

Yes, it works with the line of code of @stetim94


#12

you should give the credits to ionatan, he is the one who found this solution, but good to hear you guys made it work :slight_smile:


#13

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