Censor. Interesting problem


#1



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


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


def censor(text, word):
    new_text = ''
    for i in text.split():
        if i == word:
            new_text += '*' * len(word)
        else:
            new_text += i
        new_text += ' '
    return new_text


#2

you have an additional space at the end of your string:

"***_***_***_"

i replaced the spaces with underscores so you can it. You can slice it off, you learned string slicing


#3

Missed that space. Thank you:+1:


#4

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