10.censor!


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>
File “python”, line 8
new.append(’*’ * (len(word))
^
SyntaxError: invalid syntax
<What do you expect to happen instead?>
Even without the else statement, the code is still wrong and i got no idea!
plz help~
Thanks for inspecting my code

```python

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

<do not remove the three backticks above>

#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