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

Python Python Basics (Retired) Putting the "Fun" Back in "Function" Functions

challenge task 2 of 2

I did not understand this challenge need some help really appreciate it.

Matthew Rigdon
Matthew Rigdon
8,223 Points

More specific please. What don't you understand?

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

Challenge Task 2 of 2 asks

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.

# Now, make a function named `summarize` that also takes a list.
def summarize(lst):
    # `"X"` with the string version of the list
    X = str(lst)
    # `"Y"` with the sum total of the list.
    # use the `add_list` function from Task 1
    Y = add_list(lst)
    # 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.
    return "The sum of {X} is {Y}.".format(X=X, Y=Y)

This can be simplified to be:

# Now, make a function named `summarize` that also takes a list.
def summarize(lst):
    # 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.
    return "The sum of {X} is {Y}.".format(X=lst, Y=add_list(lst))

or using the default format notation, the return can written as:

return 'The sum of {} is {}.'.format(lst, add_list(lst))

Thanks Chris