Whats wrong with my code?


Whats wrong with my code? Why should be a dot at the end?


Oops, try again. Your function fails on censor("Yo go fro yo go","go"). It returns "yo ** fro yo **" when it should return "Yo ** fro yo **".

def censor(text, word):
    text = str(text)
    word = str(word)
    text = text.lower()
    splitted_sentence = text.split()
    for amcik in splitted_sentence:
        if amcik == word:
            text = text.replace(word,("*" * len(word)))
    return text


@sadesoda Most of your code is unnecessary. You are confusing yourself without needing to, you have the essential lines for the code in there but need to remove the rest. You only need the lines:


Ultimately, your code should look like this:

def censor(text, word):
      text = text.replace(word, ("*" * len(word)))

Hope that helps! Let me know if you need more help. Good luck and happy coding! :slight_smile:

-- @chipjumper36731


lol,that was way much easier.thanks


@sadesoda Glad to help! :slight_smile: Keep coding!


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