10. censor



def censor (text, word) :
    for w in text :
        if w == word :
            text.replace(w , ("*"*len(w))
    return text

can any one please help me?
why does it not working?
I'm getting an error

File "python", line 5
return text
SyntaxError: invalid syntax

Thank you!


look at your parentheses on the line above


Thank you!

it was wrong but now it is not working at all :frowning2:

Oops, try again. Your function fails on censor("hey hey hey","hey"). It returns "hey hey hey" when it should return "*** *** ***".


i corrected the problem you had so you can continue?


for w in text :

you loop over text, but text is a string, so w will contain letters:

def censor (text, word) :
    for w in text:
        print w
censor("hey hey hey", "hey")

how can a single letter equal a word?

Using replace is very boring, you can make a single line solution