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

0 1111111
PLUS
0 1111111
Courses Plus Student 677 Points

the question of function.py is somewhat confusing.

The question prompt has a question that is somewhat understandable, but the comments in the script are very confusing. I'm not sure exactly what's wanted.

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.
my_list = []

def add_list():
    for items in my_list:
        print('items count {}'.format(len(my_list)))
        break
print (add_list())

2 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

add_list should be a function that takes a list and adds everything in the list together. Your add_list doesn't take any arguments, so it can't pass the challenge.

0 1111111
PLUS
0 1111111
Courses Plus Student 677 Points

ok, the following passes the challenge, however, what would I do If I get a list with a lot of variables? I can't just do my_list[0]+....

my_list=[1,2,3] def add_list(x): return my_list[0]+my_list[1]+my_list[2]

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Well, we covered how to loop through a list in a previous video. So start with 0 and add the things in the list to that.