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

I dont how to proceed now


Replace this line with your code.

def censor(text,word):
new_string = ""
text = text.split()
n = len(word)
c = len(text)
m = "*" * len(word)
for i in text:
if i == word:
return new_string


You code fails due to one reason.
You're not giving space between words.

You have to put space in if part and also inelse part!(when you add i/m to new_string)
for example..
new_string+=" " + m

thou you will still get an error.
to deal with that use .lstrip() on returning string!


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