Censor


#1

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


#2

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 **********


#4

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)*"*"))
else:

just put this in to clean up the code

    return text

#5

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

This is my code.


#6

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.


#7

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