Error with Else statement in Censored


I've gotten something that, as I run through it line by line, should work. However, I keep getting two error messages. In the console, I see:

File "python", line 7
SyntaxError: invalid syntax

Meanwhile, in the editor, I see this:

Oops, try again. Did you create a function called censor? Your code threw a "global name 'censor' is not defined" error.

def censor(text, word):
    words_arr = text.split()
    final = ''
    for check_word in words_arr:
        if(check_word == word):
            final.join(" " + "*" * (len(check_word))
    return final
censor("I like apples and oranges and bananas", "and")

Admittedly, there's a pretty good chance that this is just my bonehead forgetting something simple about conditionals, but can someone please help me because I can't figure out for the life of me what it is.


You haven't close a paranthese after final.join() function.

final.join(" " + "*" * (len(check_word))

should be

final.join(" " + "*" * (len(check_word)))

Also, it is not mandatory to use parentheses in if statement.


Additionally, the .join statement can simply be:

final.join(" " + "*" * len(check_word))

No need for parentheses outside the len method.


Thanks to both of y'all!! That took care of that issue.

That said, if anybody's looking here for a solution, know that even after making the changes above, it still didn't quite work, but I was able to figure it out from here.