Censor: Error when I return the right thing


#1



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

I run my program, and it looks like it should work. I've run it with another phrase and gotten the right censorship, but I keep getting the error: Your function fails on censor("hey hey hey","hey"). It returns "*** *** *** " when it should return "*** *** ***".

It looks like I'm getting an error even though the program runs the right way. Help?


def censor(text, word):
    replacement = "*" * len(word)
    correct = ""
    text = text.split()
    for w in text:
        if w == word:
            w = replacement
        correct = correct + w + " "
    return correct


#2

lets replace the spaces in the output with a underscore:

***_***_***_

oops, you have a space at the end which doesn't belong, you either have to rewrite the solution, or just slice it off:

return correct[:-1]

slice should have been covered already