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

python function challenge task 1

How to get list out of argument space

functions.py
# 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([1, 2, 3]):
  sum = 0
  sum = 

3 Answers

Juan Martin
Juan Martin
14,335 Points

Hello my fiend,

You should do a for loop to get the each value of the list and do the sum of each one and then return it at the end. It should look like this:

def add_list(a_list):
  sum = 0
  for item in a_list:
    sum = sum + item # is the same as sum += item

  return sum

As a piece of advice, always use lowercase letters for everything except when defining classes (use just 1 uppercase letter at the beginning)

Hope this helps :)

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Joni;

I would take a look at this post to see if it helps. I thought it offered a good explanation.

Happy coding,

Ken

Need help with creating a variable named list_1 that has three items