Hello. I'm having a spot of trouble with my censor. Mind helping me out?
Here's how I'm erring:
Oops, try again. Your function fails on censor("hey hey hey","hey"). It returns "hey hey hey" when it should return "*** *** ***".
I don't understand why my code is not adding the "replacer" to the "new_word" I've created. I know the else statement adds the item by default after my replacing fails, just not why the "replacer" isn't replacing.
def censor(text, word): text = text.strip() text = text.split(',') new_word = '' replacer = '' for i in range(len(text)): replacer += '*' for item in text: if item == word: new_word = new_word + replacer else: new_word = new_word + item return new_word
Thanks for reading.