It returns "*** *** *** " when it should return "*** *** ***"


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

how to avoid the empty space at the end

def censor(text,word):
    for i in s:
        if i==word:
            t=n+" "+t
            t=t+" "+i
    return t    
print censor("hey hey hey","hey")             


@webwhiz45660: That's because you're returning a string with an extra blank space between the last letter and the last quotes.

print "Hey!"
print "Hey! "

Not much different from one another but their length sure won't be the same.
Just make sure whatever your code will follow all the given rules in the lesson.


To avoid it? I guess you need to rewrite your program, and try a different method. Here is what i would do, i would simply slice it off. remember how string slicing works?
take a look at this code:

print "the last letter is getting sliced off"[:-1]

now use this knowledge to slice of that nasty space at the end