When I attempt to run the code, it throws the following error message:
Oops, try again. Your function fails on censor("hey hey hey","hey"). It returns "*** *** *** " when it should return "*** *** ***".
I don't understand why this does not work, as the output is exactly what I have expected, "There's a lot of *** in *** sentences"
censoredlst = ["stuff", "other"] def censor(text,word): newsentence= "" sentencelst = text.split(" ") # print sentencelst for w in sentencelst: # print word if w in word: newsentence+= "*" * 3 + " " else: newsentence+= w + " " return newsentence sentence = ("There's a lot of stuff in other sentences") print censor(sentence,censoredlst)
I would greatly appreciate any responses! Thank you in advance