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 trialKelly Ferrell
2,561 PointsProblems 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
# 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:
Kelly Ferrell
2,561 PointsI did that and still it says syntaxError. Not sure why.
Nicholas Ah Kun
2,419 Pointsplease 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
Jacob Murphy
Full Stack JavaScript Techdegree Graduate 32,014 PointsPython, 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.
Nicholas Ah Kun
2,419 PointsNicholas Ah Kun
2,419 Pointsin 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.