Please tell me what’s wrong with my code. I use PyCharm and it work there


Your function fails on censor(“hey hey hey”,“hey”). It returns " " when it should return " ".

def censor(text, word):
    a = text.split()
    for i in a:
      if i ==word:
        b=b+'*' * len(word)+ ' '
    return b


There will be an issue with the trailing space if it is at the end.

>>> censor("hey hey hey","hey")
'*** *** *** '


Ok.I understand.Thank you!


2 posts were split to a new topic: Please tell me what’s wrong with my code - Censor


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