It returns "*** *** *** " when it should return "*** *** ***". Error


I guess I'm not doing it the way it wants me to because I get this error "Oops, try again. Your function fails on censor("hey hey hey","hey"). It returns "*** *** *** " when it should return "*** *** ***".

From what I can see, the two texts in the error report are exactly the same

def censor(text, word):
    count = len(word)
    t = text.split()
    y = ''
    for char in t:
        if char == word:
            y += '*' * count + ' '
            y += char
    return y


no, they are not. lets replaces the spaces with underscores, your code:


desired output:


you have a space too much at the end, you could slice it off? [:-1] is what you need for the slice, and slicing shouldn't be new at this point in the course, right?


Thanks, mate! Im sure I have learned slicing before but I just started again from a very long absence.

The new code if someone is interested, I added another space after uncensored characters aswell


Thanks man, i really learnt and solved my problem from this