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


Greg Kitchin
Greg Kitchin
31,522 Points

Putting the 'Fun' into 'Function' task 2. Help?

So I'm getting an error message saying that task 1 is no longer passing. I've not changed it from the first task. Does anyone know where I'm going wrong? I think I've done something wrong with calling add_list in the second task, but not sure.

//Task 1 lst = [1,2,3]

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

//Task 2
def summarize(lst,sum):                             
    list_to_string = str(lst)                       
    print("The sum of {} is {}.".format(list_to_string,total))

2 Answers

The function summarize only needs one argument, the list that you want to "summarize". Instead of using sum as a parameter, you can use it as a variable within the function to store the value that is being returned from calling the add_list function (also remember that you need to pass in a list to the function: add_list(lst). The way you have it right now, add_list is being called and returning a value, but nothing is being done with that number. total is a variable that is local to the add_list function, and it can't be called outside the function definition. Also, you might need to return the string instead of printing it.

Greg Kitchin
Greg Kitchin
31,522 Points

That helped a lot, thanks.