Censor


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

https://www.codecademy.com/en/courses/python-intermediate-en-rCQKw/1/4?curriculum_id=4f89dab3d788890003000096#
<In what way does your code behave incorrectly? Include ALL error messages.>

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

Not sure why
<What do you expect to happen instead?>

def censor(text, word):
    x = text.split()
    for i in x:
        if i == word:
            x[x.index(i)] = '*' * len(word)
        else:
            return ''.join(x)

#2

you should return the censored string after the loop has finished running, the whole loop needs to run to get the correct censoring


#3

just erased that else then write the return outside the for loop then put some space in the return .‘spacehere’.join(x)


#4

wow thanks it was so simple


#5