Problems with Indenting (16. Using Strings in Lists in Functions)


#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.>
https://www.codecademy.com/courses/learn-python/lessons/lists-and-functions/exercises/using-strings-in-lists-in-functions?action=lesson_resume

This is exercise 16 in “Lists and Functions”, “Using Strings in Lists in Functions.”

<In what way does your code behave incorrectly? Include ALL error messages.>
The error message I get is as follows:

File “python”, line 7
return result
^
IndentationError: unexpected indent

<What do you expect to happen instead?>
I still have problems with indentation errors at times, usually within functions just like this one, and I seldom understand why. Whenever I return a result, “return” should be indented in line with the ‘for’ statement, right? It can’t be back a tab, because then it’s outside of the function, and forwards a tab puts it within the ‘for’ statement. What am I missing here?

Thanks!

EDIT: I’ve since solved the problem on my own.

```python

n = [“Michael”, “Lieberman”]

Add your function here

def join_strings(words):
result = ""
for i in range(0, len(words)):
result = result + words
return result

print join_strings(n)

<do not remove the three backticks above>

#2

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