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

Deborah Millians
Deborah Millians
553 Points

missing how I define the function as the sum of the numbers in a list

I have watched the lesson video three times and do not understand what I am supposed to write. Beginner problems from a beginner.

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(sum 1,2,3)
Farrah Dickerson
Farrah Dickerson
10,173 Points

You've got a lot going on there:

def add_list(user_defined_list):
    return "The sum of {} is {}".format(user_defined_list, sum(user_defined_list))

sample_list = [1, 2, 3]
print(add_list(sample_list))

I hope that helps.

4 Answers

Farrah Dickerson
Farrah Dickerson
10,173 Points
def add_list(user_defined_list):
    return "The sum of {} is {}".format(user_defined_list, sum(user_defined_list))
Deborah Millians
Deborah Millians
553 Points

Thank you! I was making it too hard for the second portion of the challenge.

Deborah Millians
Deborah Millians
553 Points

Thank you both. Caleb's answer helped with the first problem. But I did get the "tuples" error for the second problem. Continuing to work second part...

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

Good to know. If I remember correctly you don't add the string in the first task. Am I right? Deborah, try changing the tuple to a list as Farrah said .

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

Does this work?

a_list = (1,2,3)

def add_list(a_list):
  output = sum(a_list)
  return output