Censor


#1

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

https://www.codecademy.com/courses/learn-python/lessons/practice-makes-perfect/exercises/censor-

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



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


#2

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

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

#3

Ok.I understand.Thank you!


#4

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


#5

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