10/15 - Censor // Why does it work only in the first run?


#1

Hello Codecademy Community. I have coded this activity a little bit like pascal style (first programming language I learned) and I wanted to know why it is not working. I don't want to check other related threads yet. Thanks in advance!


#2

@outragedwindow,

text = "this word is a text word"
word = "word"
new_text = ""
i = 0
while i <= len(text) - 1:
    test_word = ""
    if text[i] == word[0]:
        j = i
        while j <= i + len(word) - 1:
            test_word += text[j]
            j += 1
        if test_word == word:
             new_text += '*' * len(word)
             i += len(word) -1
        else:
             new_text += text[i]
    else:
        new_text += text[i]
    i += 1
print new_text