Censor - why my loop wouldn't work?


def censor(text,word):
for i in word:
if i in text:

return new_text

print censor("hey hey why","hey")

hello guys,

the code above was intended to be the basis loop for the Censor session. however, somehow the loop would not work. instead of replacing all Text Characters with "*", it would replace only the first one and won't show any other character, as could be seen from the copied screenshot. have no idea why is it. do you?

Replace this line with your code.


Hello @bokery,

Can you please post your code and a link to the exercise.That would help greatly...


thanks for commenting. it is my first post and it took me sometime to get it done. sorry.


You should set your new_text variable outside of your for loop, since it is resetting every time it iterates over text...


thanks for the fast feedback. just did it and instead of one "*" i received three "***". looks like it wouldn't run for the entire Text.


here's the revised code


You have to add the amount of asterisks as the length of the word, and also a space between the words' asterisks.


thanks for the input. will see if i can solve it now,