Censor. A small mistake that eludes me


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/4?curriculum_id=4f89dab3d788890003000096

it says that it returns " *** *** " instead of " *** ***"


def censor(text, word):
    no_of_asterisks = 0
    word_index = 0
    texts = " "
    length = len(word)
    asterisks = no_of_asterisks * "*"
    text = text.split()
    for count in text:
        if count == word:
            texts = texts + " " + (length * "*")
        else:
            texts = texts + count
    return texts


#2

I think we should first take on the first problem which is, your code doesn't censor anything I have just tested your code myself and it just returns the same string.

  1. You have a few unnecessary variables seeing as you do not use them in your code,

#3

it works now. i have just fixed it.


#4

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