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 trialKristian Terziev
28,449 Pointswhat is this function doing
Can't quite understand the task. Is it possible to give me an example of what the function is doing?
Make a function named add_list that adds all of the items in a passed-in list together and returns the total. Assume the list contains only numbers. You'll probably want to use a for loop.
I can't full understand what is required of me to do in this task. Perhaps the reason for this is that english is not my native language. I would appreciate it if you could shred some light on it.
Perhaps give an example of what happens when the function is called. Thanks in advance :)
4 Answers
Kenneth Love
Treehouse Guest TeacherYou can call the passed-in list anything you want. It doesn't matter how many items are in the list, your function only wants one argument and should loop over the entire list until it runs out. Remember us doing for x in y:
where y
was a list?
Kenneth Love
Treehouse Guest TeacherSure. I'll update the CC to show an example, but until then:
>>> add_list([1, 2, 3])
6
Kristian Terziev
28,449 PointsThank you for the quick response. But I'm afraid even with and exmaple I can't pass the challenge. Could you give me a couple of pointers. Should there be a specific argument for the function? How exactly do we know how much items are there in the list so we can sum them?
Kristian Terziev
28,449 PointsGot it now :) Thank you.