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 trialCarly Gloge
429 PointsProblem 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
Treehouse Moderator 68,441 PointsThe 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)))