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

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,033 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