Censor(the website seems to have issues)


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/4?curriculum_id=4f89dab3d788890003000096#


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,
        else:
            return len(word) * '*',


#2

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


#3

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


#4

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!

hint**
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!


#5

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