Using Strings in Lists in Functions


#1

Hello, I am struck on this.

https://www.codecademy.com/courses/python-beginner-nzzVa/3/5?curriculum_id=4f89dab3d788890003000096#

I keep getting this message File "python", line 7
SyntaxError: 'return' outside function

I then tried moving the "return result" line around a bit but nothing works.
Please help.

n = ["Michael", "Lieberman"]

Add your function here

def join_strings(words):
result = ""
for word in words:
result = result + word
return result

print join_strings(n)

Thank you.

Lemon


Replace this line with your code.


#2

I think there is problem with your indentation.
Python uses indentation to structure code blocks.
Without it,It will throw an error.
Follow this syntax...

def Yourfunction(someparameter):
    #statements
    #for loop
        #expression inside the for loop
        
    #return the final value

also a short read on indentation-
Indentation in Python

do reply if it solved the issue or not!


#3

It works.

Thank you.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.