#10 - Censor


Error-->Oops, try again. Your function fails on censor("hey hey hey","hey"). It returns "" when it should return " *** ***".

def censor(text,word):
    for x in word:
        if word in text:
        return word
    print censor(text,word)
text=raw_input("enter the text:")
word=raw_input("enter the censor word:")    
print text


a function ends the moment a return keyword is reached, this currently happens in the first iteration of your loop. Change the indent of return so the whole loop can run.

the function call should be outside the function:

def example():
   print "function call indention"

# no indent, so the function call is outside the function

you should declare the text and word variable before the function call

okay, so lets do the one the exercise suggested:

def censor(text,word):
    for x in word:
        print x

censor("hey hey hey","hey")

as you can see, x will hold the words in word one by one, but this is read only,you can't use it for manipulation. I don't see why you overwrite x with *, it doesn't make sense


if word in text:

doesn't make much sense either, this means that if the word which requires censoring in the sentence, this condition is always true, so it would censor all words.

Really take a minute to think over the logic of your program, i would almost recommend starting again


Yeah, I already solved the problem, the whole code was illogical :confused:


it was quit illogical. If you solved it before my help, please next time add a reply you already solved it :wink:


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