10. censor


#1


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

i don't understand why this code doesn't work (it doesn't even get to the print "cool" after the if statement)
i succeed when i used split but i would like to understand why this one doesn't work.
thank you!


def censor(text, word):
    print text
    for i in text:
        if i == word:
            print "cool"
            ast = ("*" * len(i))
            text.replace(i ,ast)
    return text


#2

@netaram
Then try

def censor(text, word):
    print text
    for i in text:
        print i
        if i == word:
            print "cool"
            ast = ("*" * len(i))
            text.replace(i ,ast)
    return text

#3

still not working, and also don't print the i


#4

@netaram,
Have you called the function

censor("this is a text","text")

#5

yes, it prints the i but not the final text with the **** instead of "text"

this is the error i get:

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


#6

@netaram
Try to use

 https://discuss.codecademy.com/t/10-censor/47719/2?u=leonhard.wettengmx.n

#7

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