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

challenge add_list

please help me with this challenge. how do I create this function

still dont get it though

1 Answer

Brett Vincent
Brett Vincent
3,780 Points

Define the function first using the def keyword, and it takes a list as an argument. You can just put a variable name, like blah as the argument. add_list(blah). create a variable to hold onto the sum that you can return at the end, you can just set it to 0 for now. then run a for loop to add the parts of the list together, for x in blah. during the for loop, add the part of the list you are cycling through to the variable you created. sum = sum + x. And finally return the sum. At least, that is how I did it.