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 trialNeil Gordon
8,823 Pointsnot sure I am understanding what my error is on this one. My thoughts are I can pass list_of_numbers into my function an
and call that function in return statement.
list_of_numbers = [1,2,3]
def add_list(list_of_numbers):
for item in list_of_numbers:
counter = 3
counter = counter + item
return counter
def summarize(list_of_numbers):
return ("The sum of" {} "is" {} ".".format(list_of_numbers,counter))
3 Answers
Chris Freeman
Treehouse Moderator 68,441 PointsIt looks like your def summarize
statement is indented too much. Unindent it align with the def add_list
statement.
The rest of the code is very close to correct. The format syntax was off and the counter
argument was replaced with add_list(list_of_numbers)
. I've corrected the errors:
def add_list(list_of_numbers):
counter = 0 # initialize outside of for loop
for item in list_of_numbers:
counter = counter + item
return counter
def summarize(list_of_numbers):
return ("The sum of {} is {}.".format(list_of_numbers,add_list(list_of_numbers)))
Neil Gordon
8,823 Pointsah, my logic was all wrong , will try this
Neil Gordon
8,823 PointsThat worked perfectly thanks for the help!
list_of_numbers = [1,2,3]
def add_list(list_of_numbers):
for item in list_of_numbers:
counter = 3
counter = counter + item
return counter
def summarize(list_of_numbers):
return ("The sum of {} is {} .".format(list_of_numbers,add_list(list_of_numbers)))
Neil Gordon
8,823 PointsNeil Gordon
8,823 PointsThank you for the assistance here is my new error TypeError: 'function' object is not iterable
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 PointsIn your code, you have:
You are passing the function
summarize
as an argument inadd_list(summarize)
. The function object can not be iterated upon when it get's to thefor
loop inadd_list()
.You need to pass the
list_of_numbers
from thesummarize
call as an argument toadd_list
: