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

Python Basics: Stage 5 Challenge Tasks - add_list and summarize functions

The code I am using returns "ValueError: zero length field name in format" and I can't seem to figure out the problem:

def add_list(lst):
  total = 0
  for num in lst:
    total += num
  return total

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

Here is the original question: 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.

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Just tested this original version of your code and it completely passes the CC.

3 Answers

Hi Jeff,

I think you may to convert the list to a string for the 1st argument using str():

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

However, it looks like at least this challenge is still having a problem. Someone else was having a problem earlier with this exact challenge.

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

I don't see anything wrong with your code. I'll double-check that our code challenge runner hasn't changed.

FWIW, I was able to get yours to pass by putting {0} and {1} in place of your placeholders.

Thank you, that fixed it!