I am stuck on the "censor" exercise.

When I run my code in IDLE, it works fine. However, when I submit it to the codecademy, I get this error: Oops, try again. Your function fails on censor("hey hey hey","hey"). It returns "*** *** *** " when it should return "*** *** ***".

I'm not quite sure what isn't working.

def censor(text, word):
    new_text = ""
    text = text.split()
    for i in text:
        if i != word:
            new_text += i + " "
        elif i == word:
            i = "*" * len(i)
            new_text += i + " "

    return new_text


lets replace the spaces with underscores:


you have an additional space at the end, that is why its not working


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