10. Censor - how to return?


#1

Hello guys, I would appreciate some advice on how to return the proper text.
It looks like program is working fine, except I am not able to return the "outcome".
Here is my code:

def censor(text, word):
length = len(word)
xxx = text.split()
new_string = ""
for x in xxx:
    if x == word:
        print ("*" * length) + "".join(new_string),
        continue    
            
    else:
        print "".join(new_string) + x,
return new_string

word = "hey"
text = "hey hey hey"
print censor(text, word)


#2

@themafi,

def censor(text, word):
    length = len(word)
    xxx = text.split()
    new_string = ""
    for x in xxx:
        if x == word:
            print ("*" * length) + "".join(new_string),
            #continue    
            
        else:
            print "".join(new_string) + x,
    return new_string

word = "hey"
text = "hey hey hey"
print censor(text, word)
print censor("this test is testing the test", "test")

#3

@leonhard_wettengmx_n
Hey Leon, Thanks for the reply.
However, it still returns following:
Oops, try again. Your function fails on censor("hey hey hey","hey"). It returns "" when it should return "*** *** ***".


#4

You don't save ur awnser into the new_string. You only print the outcome.