Whats wrong with my code?


#1



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

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


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


#2

@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:

and

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


#3

lol,that was way much easier.thanks


#4

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


#5

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