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

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
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!