10. Censor


#1



Hi All!
I've read these topic in other posts, but couldn't find the answear for my code.


I wrote the code, which is below. The error is:
Oops, try again. Your function fails on censor("hey hey hey","hey"). It returns "hey hey hey" when it should return "*** *** ***".


Can you help we with guiding to the solution?


def censor(text, word):
    new_text = text.split()
    censored = ""
    for w in new_text:
        if w == word:
            w = "*" * len(word)
        else:
            censored += w
    result = ' '.join(new_text)
    return result


#2

here:

result = ' '.join(new_text)

what is stored in new_text?


#3

splitted text with word (w) changed in loop
maybe looping wasn't saved in new_text?


#4

I managed :slight_smile: I changed "if's" content and order

if w == word:
censored += "*" * len(word) + " "

    (...) and

' '.join(censored)
return censored[:-1]

#5

very good, that was the point i was trying to make :wink:

very good you managed it :slight_smile: Even better that you fix it yourself


#7

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