Censor


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

why my code doesnt working.......?
help


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


#2

you split text into a list, but don't store this list into a variable? So text is still a string


#5

Text remains a string type if doesn't store it in a variable. And then would you concatenate strings?


#6

When you make for loop, you go through string, counting LETTERS, not words. How supposted to be equal any letter with second input WORD? Its like 'a' == 'hack'.
So i would recommend you:
1) make empty LIST as 'new' variable , not string. new = []
2) make this: text = text.split() also, it will connect split result to variable.
3) new += a When you add your operation into list better use append method here, because += will add letters into list instead words. new.append(' * ' * len(word)) ( i made extra spaces to show how i separated this, you should use standard synthax)


#7

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