10. censor


#1



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


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!


#2

look at your parentheses on the line above


#3

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 "*** *** ***".


#4

i corrected the problem you had so you can continue?

here:

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