I am currently learning on Codecademy and can't get past one problem:
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.
My code is:
def censor(text, word):
word_converter = ("*" * len(word))
words = text.split()
print(words)
for bad_word in words:
if bad_word == word:
words.replace(bad_word, word_converter)
print(words)
censor("What the curseword is that", "curseword")
This is what is returned:
Traceback (most recent call last):
File "C:\Users\andre\PycharmProjects\fun\main.py", line 10, in <module>
censor("hello i am andrew", "hello")
File "C:\Users\andre\PycharmProjects\fun\main.py", line 7, in censor
words.replace(bad_word, word_converter)
AttributeError: 'list' object has no attribute 'replace'
I don't understand why the replace
function does not work.