Granger Obliviate Granger Obliviate - 1 year ago 108
Python Question

Python - CodeAcademy: censor

I'm currently solving "censor" form Practice Makes Perfect of the Python course on CodeAcademy.

However I'm facing an error and I don't know how to solve this. I looked to my code multiple times and I can't understand what's wrong.

Here's my code:

def censor(text, word):
text = text.lower()
word = word.lower()
word_censored = '*' * len(word)
textlist = text.slip()
newtextlist = []
for stuff in textlist:
if stuff == word:
return "".join(newtextlist)

And the error that shows up is:

Oops, try again. Your code looks a bit off--it threw a "'str' object has no attribute 'slip'" error. Check the Hint if you need help!

Can someone give a hint on what's wrong?

Answer Source

First of all, slip() should become split() . Python does not have a string function named slip().

Also, the last line should be " ".join(newtextlist) because Python doesn't know you're forming a sentence with a space between then. It puts one word right after the other.

Thirdly, be sure to indent newtextlist.append(stuff), as well as removing the lower() calls. There are no instructions given that the result must be in lowercase, so this is not needed.