Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics (Retired) Putting the "Fun" Back in "Function" Functions

Practice functions. Bad return

I made this code:

_list = [] def add_list(num): _list.append(num) return(sum(num))

def summarize(num):

return ("The sum of {} is {}.".format(_list,(sum(num))))

and the return is like this : The sum of [[1,2,3]] is 6.

How do I fixed to get only [1,2,3]

functions.py
# add_list([1, 2, 3]) should return 6
# summarize([1, 2, 3]) should return 
# Note: both functions will only take *one* argument each.
_list = []
def add_list(num):
  _list.append(num)
  return(sum(num))

def summarize(num):


  return ("The sum of {} is {}.".format(_list,(sum(num))))

1 Answer

Iain Diamond
Iain Diamond
29,379 Points

Hi Eric, The only change required is in function summarize(), such that it prints out the input parameter, num, as shown below.

# add_list([1, 2, 3]) should return 6
# summarize([1, 2, 3]) should return 
# Note: both functions will only take *one* argument each.
_list = []
def add_list(num):
  _list.append(num)
  return(sum(num))

def summarize(num):
  return ("The sum of {} is {}.".format(num,(sum(num))))

print(add_list([1,2,3]))
print(summarize([1,2,3]))

Hope this helps, iain