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

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

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

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

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 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,009 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,441 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.