16/18- Using strings in lists in functions


#1

Hello. I am slightly confused as to why it throws this error at me:

  File "python", line 8
SyntaxError: 'return' outside function

I don't see any indentation problems with my code:

n = ["Michael", "Lieberman"]
# Add your function here
def join_strings(words):
    result=""
    return words
for i in range(len(words)):
    result = result.join(words)
    return result
print join_strings(n)

Thanks in advance for helping :smiley:


#2

i don't understand this, you declare a function, define a empty string and then return words, why? i am talking about this lines:

def join_strings(words):
    result=""
    return words

then your for loop is not in your function, why?

def join_strings(words):
    result=""
    return words
for i in range(len(words)): <- no indent in this line, so it is outside the function

so your second return (return result) is not in a function, a return should be inside a function.


#3

Thanks for this. I didn't read the instructions carefully. I needed the for loop with the def function and got confused because i had the for loop separated.