10. censor


10. Censor

I cannot get the code to iterate past the first example.

I expected it to print a new list in new_text with the "hello" bleeped out.

def censor(text,word):
    text_split=text.split( )
    for i in range(len(text_split)):
        if text_split[i]==word:
            return new_text.append(len(word)* "*")
            return new_text.append(text_split[i])
print censor ("hello young lovers!","hello")
print new_text


a function ends the moment a return keyword is reached, so your function ends in the first iteration of the loop

so you want to return after the loop

also, don't forget to .join() the list into a string before returning it

make sure to place everything you need inside the function


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