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

Now, make a function named summarize that also takes a list. It should return the string "The sum of X is Y.", replacing

may somebody please help me ive been stuck on this for ever and i need to pass my class

functions.py
def add_list(lst) :
  result = 5
  for item in lst:
    result += item
    return result 

3 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

From the Putting the Fun Back in Functions Challenge Task 2 of 2 :

Now, make a function named summarize that also takes a list. It should return the string "The sum of X is Y.", replacing "X" with the string version of the list and "Y" with the sum total of the list.

def summarize(list_in):
    # Set X to input list
    X = list_in
    # Set Y to sum of items in list using add_list() function
    Y = add_list(list_in)
    # return string
    return "The sum of {} is {}".format(X, Y)

This can be compress into a single statement:

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

so just do the bottom part

chris freemen this didn't work it says name error name summarize is not defined

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

Hi Alec, you seem to have two threads on this topic. I think summarize() isn't being seen due to the indention error mentioned in the other thread