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

function

Why is the following code wrong?

def add_list(list_x): sum(list_x)

When I try it in the shell it works fine; however, it appears to be wrong answer in the quiz.

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(list_x):
  sum(list_x)

3 Answers

Seth Reece
Seth Reece
32,867 Points

You could also do it the long way as the challenge suggests:

def add_list(list):
  i = 0
  for item in list:
    i = i + item
  return i
Seth Reece
Seth Reece
32,867 Points

Hi Sclaudina,

Your function needs to return something when it is called. e.g.

function add_list(list):
    return sum(list)
Kenneth Love
Kenneth Love
Treehouse Guest Teacher

I think you mean def instead of function. Been doing JavaScript lately?

I tried as you indicates and also using print() like: def add_list(list_x): print(sum(list_x)) In both cases the answer to the quiz appears to be wrong. However, it works fine offline.

Thanks a lot for your kindness.