Censor help


#1



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

Censor help
15. Practice Makes Perfect


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


My code seems to only be going through the first word, then stopping, would someone mind helping me out


def censor(text, word):
    text = text.lower()
    split = text.split(" ")
    length = len(word)
    print (split)
    new = ""
    for i in split:
        if i == word:
            i = ("*" * length)
        return i
    print " ".join(split)


#2

For starters, we do not need to convert to lowercase.

It is rarely a good idea to use a function name as a variable.

This will not change the list.

Inside the loop; too much indentation.

That's a few things to adjust. You might work out the rest in the meantime.


#3

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