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


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/4?curriculum_id=4f89dab3d788890003000096

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):
    t=""
    s=text.split()
    for i in s:
        if i==word:
            n="*"*len(word)
            t=n+" "+t
        else:
            t=t+" "+i
    return t    
    
print censor("hey hey hey","hey")             
         .


#2

@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.


#3

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