10. Cencor


#1

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!


#2

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


#3

Oh I see, thank you for helping me out!


#4

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


#6

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