Censor - weird error



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

I am confused - why does the error say it returns "the password is **** *** *** ***" when the text checked does not mention anything regarding any of this text?? It is just "hey hey hey" there as text

Here is my code, for reference:

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


That's a very strange error. Your code appears to be correct and, like you said, says nothing about a password or any of that. Have you tried reloading the page?


Yup - just tried again. Also tried changing some info like the names of variables, copying than reseting the code than pasting... does not work


I have no idea why it was throwing that error, perhaps someone else can shed some light on that, but I did notice one problem with your function. The result list is stored outside of the function when it should be inside the function since it's part of the process of censoring.

If you move result = [] inside the function then it should resolve the error.


Wow - thanks! It worked! Never thought of that since I had it defined before the function in every exercise so far.


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