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

Problem with my Python code to make functions.

My code doesn't pass the second part of the quiz. Can anyone help?

Here's the question: Challenge Task 2 of 2

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.

Here's my code - the first part for 'def add_list(my_list):' works to add all numbers in my_list. I can't figure out how to make the 'summarize' function work.

def add_list(my_list):
    sum = 0 
    for num in my_list:
        sum += num 
    return sum

def summarize(my_list)
   return ("The sum of {} is {}.".format(' '.join(my_list),add_list(my_list)))

[MOD: added ```python formatting -cf]

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,064 Points

The parameter my_list does not have to be joined before used in formatting the string. Try:

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