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

Putting the "Fun" back in "Function"

I am stuck on the second part of this challenge. I think I had it right but when I run it I find that I don't have it right any help is appreciated.

def add_list(list): sum = 0 for number in list: sum = sum + number return sum

def summarize(list): "The sum of X is Y."

2 Answers

Juan Martin
Juan Martin
14,335 Points

Hello Brett :)

You did all great! The only thing missing is that you must put curly braces followed by a format function in your summarize function answer just as Brittany explained. The code should be like this:

def add_list(list_1):
  total = 0  
  for items in list_1:
    total+=items #it's the same as total = total + items
  return total

def summarize(list_1):
  return "The sum of {} is {}.".format(list_1,add_list(list_1)) #the value of list_1 will show where the first {} are and add_list(list_1) on the second {}

Another thing is that I recommend you to change your variables "list" and "sum" as they are the built-in types for list and sum. You can realize that when you type them in the workspaces as they turn "black" instead of "green" or "red" instead of "blue" in the code challenge.

Hi Juan,

You're missing the period at the end of the string. "The sum of {} is {}."

Juan Martin
Juan Martin
14,335 Points

Hi Jason :)


When you want to stick values into a string you use some thing like "Hello {0}".format(name).

You put your string and then put curly braces where you want to put a value in. You then add .format followed by the arguments you want to pass in. The number in the curly braces represents the index of an item in the format arguments list.

So you are going to want to replace X and Y with curly braces that have indices in them. The indices are going to represent the list and sum values you pass into the arguments for format.

Hope that helps!