15. Censor Right answer but still shows error


#1



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


My code gets the right answer but it still shows this error:

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

What is wrong?


def censor(text,word):
    string = []
    for w in text.split():
        if w == word:
            string.append('*' * len(word) + " ")
        else:
            string.append(w + " ")
    return ''.join(string)


#2

Use the join() statement to insert a space separator. Don't include the space character in your .append() statements.


#3

Thanks so much!! :grinning:That question was really bugging me.


#4

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