Censor


#1

Hi, Guys. Whats wrong with my code:

def censor(text,word):
    text = text.split()
    for word in text:
        if word in text:
            word == '*' * len(word)
    return " ".join(text)

#2

word contains the word you need to censor, so using it here:

for word in text:

is very unwise. then this condition:

if word in text:

i would use equal instead of in, of course all the words are in text, you are now censoring everything.
then this line:

word == '*' * len(word)

word is a variable which exist in that particular run of the loop, each run of the loop its gets overwritten, and cease to exist the moment the loop is finished. You might want to append it to a list or something.