Hi @yushan6714638042 - welcome to the forums.
It helps, especially with Python, if you use the code </> button to format your code. Otherwise we lose the whitespace.
I think it’ll help you to think about what you’re trying to do in a non-code sense, before trying to implement it in code.
The goal is: for a given string, find any instances of a given word and censor them
- Get the string, and the word, and pass them to the censor function. (
def censor(text, word))
- For each word in the sentence, check if it’s the target word. (A
for and an
- If it is, replace the word. (Write some code to do the swap.)
Your function doesn’t do anything to the sentence you’re given (the value
text), so it will never change anything.
If you can work out the steps you’ll have to follow to complete the exercise, you’ll be able to implement them fairly easily in Python.