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

Functions

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. where exactly am i going wrong on this one????

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.
add_list=sum
def summarize (list):
  return "The sum of {} is {}.format(str(list), sum(list))

1 Answer

Matthew Rigdon
Matthew Rigdon
8,223 Points

Make sure when you define a function that you write it like this with no space:

def summarize(list):

The only other issue you have is in this part of the code:

return "The sum of {} is {}.format(str(list), sum(list))

You have beginning quotation marks, but you never have a closing quotation mark. Right now, Python is assuming that all of that is a string, but it doesn't know where the string ends. To fix this, try this:

return "The sum of {} is {}.".format(str(list), sum(list))