Censor


#1



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

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

Hello,

I don't know how to make it right and Im not sure whether I can use my code or just think of a different solution, because it seems as if I was almost there, but maybe I'm just wrong. I guess the main problem is the "word_whole", it probably should not be there, but then the result would be "***" , that is only one word replaced(?) I don't understand why the "for loop" doesn't work for every word in the list.

Thanks for any advice!


def censor(text,word):
    text = text.lower( ) 
    words = text.split(" ") 

    for i in words:
        ln = len(i) 
        word_ast = "*" * ln
        word_whole = word_ast * len(words)
        
        if i.isalpha():
            return word_whole
            
    s = " "        
    return s.join(words) 
    return censor(text,word)


#2

the instructions gives an example:

censor("this hack is wack hack", "hack")

should return:

"this **** is wack ****"

as you can see, we don't want to censor every word in the sentence. Your code seems to censor ever word in the sentence.

I think you will need to redesign part of your code.


#3

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