Write a function called censor that takes two strings, text and word, as input. It should return the text with the word you chose replaced with asterisks.
censor("this hack is wack hack", "hack")
"this **** is wack ****"
Assume your input strings won't contain punctuation or upper case letters.
The number of asterisks you put should correspond to the number of letters in the censored word.
When len(text) and text.index(s)+1 are the same (which happens, check), it should not add a space to the next word, instead, what happens is that it adds it either way.
def censor(text, word): text = text.split() new_text = "" for e in text: if e == word: w = text[text.index(e)] = ('*' * len(e)) for s in text: print text print int(text.index(s)+1) print int(len(text)) if len(text) == text.index(s)+1: new_text += s else: new_text += s + " " text = "".join(text) return new_text print new_text print censor("Steven and Javo", "Steven")