Censor


#1



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

I dont how to proceed now

`python

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:
new_string+=m
else:
new_string+=i
return new_string


#2

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.
hint**
to deal with that use .lstrip() on returning string!


#3

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