Censor(the website seems to have issues)



I am using PyCharm (a program by JetBrains) to create projects using python. I finished the project in PyCharm and just copied and pasted it in codecademy. Although everything works fine in PyCharm, codecademy gives me an error saying: Your function fails on censor("hey hey hey","hey"). It returns "('',)" when it should return " *** ***".

def censor(text, word):
    if isinstance(text, str):
        words = text.split(' ')
    for w in words:
        if w != word:
            return w,
            return len(word) * '*',


This specific question have asked to return the censored string. so even your solution works ,It does not fulfill conditions of question and thus while you're not returning anything but printing ,it(function) simply returns None


Oh yes it seems I have pasted the wrong code in the topic but I have written in codecademy is return not print.


Ok i just seen your updated code(with return),
Now when the function hits the return(after any of the condition matches),It will return that value, halt the execution and thus will not check all the cases!
so still error exists!

One of the approach can be..
Use an empty string to append both of the o/p's fromif/else body, then convert this list back to string and return the string!


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