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!
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
Ahmed ElsaweyCourses Plus Student 3,527 Points
Can someone explain the question for me please and show me how to do the answer as well because I am new to python
how can I make this function work according to the question that I have been given
# 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(list): total = 0 for number in list: total = total + number return total def summarize(list): x = list.split() y =
Ricky Catron13,023 Points
Step one. Think about what you need to return from summarize. It expects a string so what I would do would be place return "The sum of [1, 2, 3] is 6." at the end of the function.
Then think about the values in that string [1,2,3] is the example list passed in, but we already have that in a variable called list so we can take out [1,2,3] and instead use "The sum of " + list + " is 6."
But now the 6 might not always be right, happily we already have a function to calculate that number for use! So what I would do next is change the 6 to add_list(list) like so "The sum of " + list + " is " + add_list(list) + "."
This should be the final answer and you wont need that list.split() or the x and y variables.