Censor Issue with Arguments


#1

Here's my code:

def censor(text, word):

text = text
word = word
textLength = len(text)
lenWord = len(word)
for i in range(textLength): # for each letter in the text
    if text[i] == word[0]:  # if the letter = first letter in word
        for j in range(lenWord): # for the length of the word
            if text[i + j] != word[j]: #if the letters match up
                break
        else:
            for k in range(lenWord):
                text[i + k] = "*"

return text

I'm getting the error message: "Oops, try again. Does your censor function take exactly two arguments, a text string and a word to replace with asterisks? Your code threw a "'str' object does not support item assignment" error." and I don't know why. Can someone help?


#2

@arcrunner20606

Please begin to format your code correctly when you post, as it makes it easier for us to help you. However, I will attempt to help.

I'm not exactly sure what your code is doing, but the error described suggests that somewhere you have a variable that needs to be converted into a string that is another type of variable. Fix this by finding that variable where the error is and typing str(variable). The variable I wrote would be where you put yours. Hope this helps. :snake: