Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics (Retired) Putting the "Fun" Back in "Function" Functions

Kelly Ferrell
Kelly Ferrell
2,561 Points

Problems with the list function task. IndentationError: added_list = [1,2,3]

I don't know what I did wrong. def add_list(): added_list = [1,2,3] for added_list in add_list

functions.py
# add_list([1, 2, 3]) should return 6
# summarize([1, 2, 3]) should return "The sum of [1, 2, 3] is 6."
# Note: both functions will only take *one* argument each.
def add_list():
added_list = [1,2,3]
for added_list in add_list:

in Python, indentation is extremely important. 'def' is a keyword defining a function. to create a function code block all statements in the function must be indented (the same amount of spaces, 4 is recommended).

Simply add 4 spaces before the 'added_list' and 'for added_list' statements.

Kelly Ferrell
Kelly Ferrell
2,561 Points

I did that and still it says syntaxError. Not sure why.

please repost your code.

The other issue is you're trying to iterate a list as a recursive function (yes that sounds weird).

You should be saying 'for item in added_list: ' then you can do something with 'item'

add_list is a function. the 'for' loop doesn't iterate through functions (unless if your function returned an iterable).

1 Answer

Python, unlike other languages, is very picky about indentation. Your code is fine, but anything inside a code black's : should be indented four times consistently. For more info on indentation styles here's a link to PEP8 style guides.

http://legacy.python.org/dev/peps/pep-0008/#indentation