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 "" when it should return " *** ***".


Shouldn't it go through all of the words and return the correct thing?


def censor(text, word):
    c = text.split(" ")
    b = len(word)
    censored = []
    for piece in c:
        if piece == word:
            return "*" * b 
        
        else:
            return piece
 
    s = "".strip()
    print s
    
print censor('hello there', 'there')


#2

return terminates a function whenever a return occurs function ends at that moment.

can you think where does it happen in your function?

also you created a empty list named censored but you didnt' use it.make it useful.


#3

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