Censor(function)


#1


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


I see this is in console: ( which looks right)

this **** is wack ****


None

I see an error:

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


Here is my solution:

def censor(text, word):
    words = text.split()
    for i in range(len(words)):
        if words[i] == word:
            words[i] = len(word) * '*'
    print ' '.join(words)
    
censor("this hack is wack hack", "hack")
censor("hey hey hey", "hey")

See output in console window: which looks right.


#2

Instead of printing, try return.


#3

Yes, that did the trick :slight_smile:

thank you!


#4

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