Censor 10/15


#1
def censor(text,word):
    new=[]
    count= " "
    new=text.split()
    for i in new:
        if(i==word):
            count+= '*'*len(word)+" "
        else:
            count += i + " "
    print count
    
censor("I live in city of Joy kolkata ","city")

this code runs perfectly in my IDE but throws a error in the console.
Can anyone explain why?


#2

lets say we have this function call:

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

and we would call your function, the result would be:

***_***_***_

i replaced the spaces with underscores, as you can see, we have an additional space at the end of our sentence, that is not suppose to be, which is why you get an error


#3

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