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

Joris Eckrich
Joris Eckrich
586 Points

Hi, I dont get the task. Can you please give me a hint?

Hi, I dont get the task. Where does the list come from? Thanks in advance!

functions.py
# 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():

2 Answers

Sean T. Unwin
Sean T. Unwin
28,690 Points

The list would be passed when the function is called.

The app code could be similar to:

example.py
# add_list function
def add_list(lst):
    # A variable may be handy here
    # Loop through each number in the list
        # Add current number to previous number
    # Return sum

# Define a list
my_list = [3, 5, 7]
# Store the sum of the list
list_sum = add_list(my_list)
print('List Total: {}'.format(list_sum))
Joris Eckrich
Joris Eckrich
586 Points

Thanks a lot! Your comment was really helpful!

Sean T. Unwin
Sean T. Unwin
28,690 Points

You're welcome. Happy to help. :)