Hey everyone, I'm stuck at the 'Censor' exercise in 'Practice Makes Perfect'
The error that I'm running into is that my program returns 'None' and I'm really at a loss to understand why. When I look at lots of other examples of loops, it's not as though each one 'returns' every single value. When do I know when I should type 'return' or how exactly to do the for-loop with an if-statement.
For starters, I expected this to:
Change the word into a collection of asterisks that were the same number as the length of the word.
Then split the string given in the 'text' portion of the function.
Then for each string in the split text, if one of the strings is equal to the word, it would get the index of that string, and then replace the string with the censor word.
Then it turns the list with the replaced word into a string.
Then it joins it all together at the end and returned the joined version of the text.
def censor(text,word): censor_word = '*' * len(word) split_string = text.split() for item in split_string: if item == word: split_ind = split_string.index(item) new_text = split_string.insert(split_ind, censor_word) new_str = str(new_text) joined = "".join(new_str) return joined