10. Cencor


I'm in trouble with this one and I would like to get some help with it.
My code is following:

def censor(text, word):
    words = text.split()
    for words in word:
        text=word.replace(word, "*** ")*len(word)
        " ".join(word)
        return text

I get an error message:
"Your function fails on censor("hey hey hey","hey"). It returns "*** *** *** " when it should return "*** *** ***".

I don't figure out what is wrong with the output!


why use word.replace()? i thought you wanted to censor the string stored in text

join doesn't do anything at the moment

a function ends the moment a return keyword is reached, if a return keyword is reached in a loop, the loop simply breaks so the function can end

you have a space at the end of your string:


i replaced the spaces with underscores, see the space at the end which shouldn't be there


Oh I see, thank you for helping me out!


go puzzle with the information i provided you, if after you felt like you puzzled enough and still haven't solved it, post an updated version of your code + question + error message here and i will help you further


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