Oops, try again. Your function fails on censor("hey hey hey","hey"). It returns "*** *** *** " when it should return "*** *** ***".
def censor(text, word):
new_text = ''
for i in text.split():
if i == word:
new_text += '*' * len(word)
new_text += i
new_text += ' '
you have an additional space at the end of your string:
i replaced the spaces with underscores so you can it. You can slice it off, you learned string slicing
Missed that space. Thank you:+1:
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.