10.censor!


#1



File "python", line 8
new.append('*' * (len(word))
^
SyntaxError: invalid syntax

Even without the else statement, the code is still wrong and i got no idea!
plz help~
Thanks for inspecting my code


def censor(text, word):
    new = []
    a = text.split()
    for x in range(0,len(a)):
        #iterate x for len(a) tim
        if a[x] != word:
            # a[x] is the value of list a, for x = 0,1,2.... 
            new.append(a[x])
        else:
            new.append('*' * (len(word))
            #append * for len(word) times


#2

You just need to close your last append by adding a )


#3

thanks for your reply but still error

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


#4

This is because you're not returning anything.


#5

Thank you!!
finally i got the correct answer!
Here is my code for other who get stuck!

def censor(text, word):
new = []
a = text.split()
for x in range(0,len(a)):
#iterate x for len(a) tim

    if a[x] != word:
        # a[x] is the value of list a, for x = 0,1,2.... 
        new.append(a[x])

    else:
        new.append('*' * (len(word)))
        #append * for len(word) times
latest = " ".join(new)
return latest

#12