Hi everyone, getting stuck on the censor exercise. Basically my answer is adding a space to the last word. Am not sure how i can make my code not add a space if it is the last word. Any ideas? I could do return result[0:len(result)-2] but am not sure why i am getting an error on that too. Any help is appreciated!!
def censor(text,word): result = "" for x in text.split(): if x == word: for x in range(len(word)): result += "*" result += " " else: result += text result += " " return result
Getting this error:
Oops, try again. Your function fails on censor("hey hey hey","hey"). It returns "*** *** *** " when it should return "*** *** ***".