Censor


#1

def censor(text, word):
words = text.split(" ")
new_word = ""
for i in words:
if i != word:
new_word += i + " "
else:
new_word = new_word + ('*' * len(i)) + " "
print new_word
return new_word

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

This code gives the required output, yet doesn't pass the terminal's test assessments, can anyone tell me why?


#2

there is an additional space at the end of your string/sentence, that is why it isn't working

you can use string slicing to get rid of it


#5

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