Censor activity not accepting working answer

The censor exercise is not accepting my answer, despite it working just fine. Here is my code:

def censor(text, word):
  result = ""
  for w in text.split(" "):
    if w == word:
      result += "*" * len(word) + " "
      result += w + " "
  print result

Calling censor( “this hack is wack hack”, “hack”) censors both instances of “hack” in the same format illustrated in the instructions. I don’t understand why it wouldn’t be acceptable. Can anyone help?

Thanks in advance!

1 Like

what are the exact directions and what’s the error message it’s giving you?

sometimes it’s specifically pedantic but often it’s for a good reason.

You can see the exact directions by following the posted link. The error message was,

" Your function fails on censor(“hey hey hey”,”hey”). It returns “None” when it should return “ *** *** ***”." This is not true however, as when I test that string myself, it does indeed censor each “hey”.

Following the link only takes me to the initial chapter (i’m not going to do the exercise, haha).

As for the problem, if you click view solution, you can try to compare the solution code with your own to see what exactly is the discrepancy. I usually don’t waste too much time when I realize it’s this type of error (often because of something very pedantic).

Ah, I didn’t realize the link wouldn’t work for everyone. I think I’ll take your advice and view the solution. Thanks again!

No problem, I’m almost finished with the python 3 cs career path so I’m also not familiar with the particular python 2 problems. Sorry I can’t be of more specific help.