Censor


#1



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


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


I can´t seem to figure out why my code doesn´t return something.


def censor(text, word):
    newtext = text.split()
    for string in newtext:
        censor = "*" * len(string)
        if string == word:
            newtext.remove(string)
            newtext.append(censor)
            text = " ".join(newtext)
        else:
             text = " ".join(newtext)
    print text


#2

Remember to return something, else the return value is None.


#3

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