Censor: Error when I return the right thing



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


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