Hi,Could any one help me to solve his program?


You are on the censor lesson, I don't think you understand what you are required to do. Please pay attention to the instructions to the lesson. :slight_smile:

You are supposed to take a string,

censor("I like Codecademy", "Codecademy")

this should return,

=> I like **********


Hi, you are getting there, please find below the way I have done it.

define function

def censor(text, word):

set up a if, to look for the word in the text

if word in text:

replace the word in the text, with ** which match the number of characters in the word

    return text.replace(word, (len(word)*"*"))

just put this in to clean up the code

    return text


def censor(text, word):
text = text.split()
a = []
for w in text:
if w == word:
return " ".join(a)
print censor("hey hey hey","hey")

This is my code.


Thank you. For your patience, I have been trying this code for 3 days. Your post helped me to solve the program. I really thank you for spending your valuable time to help me.


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