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 trial3 Answers
Melih Mucuk
2,118 Pointstry with following:
# add_list([1, 2, 3]) should return 6
# summarize([1, 2, 3]) should return "The sum of [1, 2, 3] is 6."
# Note: both functions will only take *one* argument each.
def add_list(number):
return sum(number)
def summarize(mylist):
return "The sum of {} is {}".format(str(mylist), add_list(mylist))
Micah Fullerton
1,850 Pointswhat's the task?
kristopherrusso
307 PointsKent,
The solution posted by Melihmucuk is accurate. I just wanted to add a little more to it. First, you want to define the function that they are asking for, add_list(). Define this function and have it take just a single argument just like the comments in the text editor state. There is a sum() method that can be used to get the sum of the list. Melihmucuk shows this in the second line of his add_list() function.
As for the second function, summarize()...you define the function first. The second line uses the return command with a call to the format() method for the two items we want to be dynamically returned. We use the {} curly braces so that we can dynamically create a string that is returned rather than hard code a string that may or may not reflect the actual sum of the list. This could be confusing to end users if we hard coded values in a string and they are not seeing results consistent with their input (NOTE: no input required for this code challenge, but mentioning just for the bigger picture).
Let me know if you have any other questions.
Kris