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

Nancy Melucci
PLUS
Nancy Melucci
Courses Plus Student 36,143 Points

Not iterable function code challenge question 1

What am I missing to make this function work? Hint? Thanks in advance...

def add_list(num):
  for num_list in add_list:
    num_list.append(num)
    return sum(num_list)

2 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Where did the add_list in your for loop come from? To solve this one, there's two general approaches. One, just use sum() on the list that's passed in (your function takes that as the argument num) and return that. Two, make a new total (or whatever) variable that's assigned to 0. Then, for each number in the list, add that number to total. Then return total at the end.

Nancy Melucci
PLUS
Nancy Melucci
Courses Plus Student 36,143 Points

I was struggling with this because you've given a lot of autonomy here compared to the shopping list exercise. I'll be back to it very soon. Little by little I will finish this course. I am taking for credit community college classes in coding and website design. Treehouse is enormously helpful...

BTW my shopping list had: eggs, bacon, spam, spam, spam, spam, spam, Lobster in a butter garlic reduction sauce and spam. (Once I got the SHOW to stop popping up....) NJM

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

There is definitely a lot of autonomy. Glad you're making your way through it!