Hi, thank you. Let me try to cover it then.
This is the exercise:
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.
This is my code:
def censor(text, word):
if word in text:
text.replace(word, "*" * len(word))
I expect it replaces the word in the text with as many asterisks as long the word is. In contrary to this, I receive the following error message:
“Your function fails on censor(“hey hey hey”,“hey”). It returns “hey hey hey” when it should return " *”."
So it seems my code does not change the text, however it should be and I do not understand why. I inserted print commands to see what the inputs are and what my function returns and it seems the error message is right, my function returns the original input. I am wondering why the “text.replace(word, “*” * len(word))” does not do what it should.
Regarding the explanation, now at least I understand that replace() does the censoring by itself so creating the function is pointless. Still I don’t understand why my code does not work…
Thanks for your reply in advance.