Censor, help


#1



Hi, got problem with my code :


Your function fails on censor("hey hey hey","hey"). It returns " *** *** *** " when it should return "*** *** ***".


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

`


#2

you have an additional space at end of the string, you learned string slicing, you can use it to get rid of the additional space at the end of your string


#3

You could also use .trim() at the end of your string to remove the spaces


#4

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