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

I feel I'm doing something very wrong but I'm not sure what... return("the sum of [arg] is Y")

I know what I want it to do but not how to make it work... lol

# 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(num):

def summarize(numb):
  return("The sum of %d is %d."(numb, sum(numb))

2 Answers

Chris Freeman
Chris Freeman
Treehouse Moderator 68,033 Points

In your summarize function, you are casting the numb argument as a decimal value using '%d'. Instead, cast it as a string:

def summarize(numb):
  return("The sum of %s is %d."(numb, sum(numb)))

# or use the '.format' method
def summarize(numb):
  return("The sum of {} is {}.".format(numb, sum(numb)))

Additionally, this challenge intends for you to solve the add_list challenge using a loop instead of the sum function.

EDIT: added missing closing paren as mentioned by Michel van Essen

Thank you very much.

Michel van Essen
Michel van Essen
8,077 Points

Great help, thanks! Just for those who are struggling as well, the last line is missing a closing parenthesis

jason chan
jason chan
31,008 Points
def add_list(lst):
    # set our current total to 0.
    total = 0
    # for each item in the passed-in argument 'lst'...
    for item in lst:
        # added each item to the total
        total = total + item
    # return current total value
    return total
Chris Freeman
Chris Freeman
Treehouse Moderator 68,033 Points

This doesn't answer the OP question which is asking about formatting of the return statement.

This does however illustrate the intended solution for add_list that uses a loop instead of the sum function

Thank you for the insight into the intended solution.