Function prints correct message but not working


Can somebody explain, why the program doesn’t accept my code?

It goes as follows:

def censor (text, word):
  if word in text:
    my_text_split = text.split(" ")
    for i in range(0, len(my_text_split)):
      if my_text_split[i] == word:
        my_text_split[i] = "*" * len(word)
    text = " ".join(my_text_split)
    print text  
censor("hey hey hey", "hey")

The error message at the bottom says that the code doesn’t return the correct result for the string “hey hey hey”. Since it returns “*** *** ***” which should be correct I can’t quite grasp what’s wrong with the code

Thx for your help

How can I use split( ) to make censor?

the error message is accurate, your function only prints the censored string and returns None (implicitly)


Be sure that your return statement is not inside the if or the for.


given print is at the correct spot, i don’t think this will be a problem for cj19954


Is it though?


The return can’t go there since it would be inside the loop body.


the print is fine in my case:


i literally copy pasted the code. Its just not returning.


D’oh! I stand corrected. Text is joined already. What was I thinking? The return statement still stands, though.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.