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

How do I make a funcwtion add_list to return the numbers added in a list? I used sum() but cannot write in a function

I am able to use the sum function in the workspace when I make a list but when it comes to actually making a function with the challenge I don't know how to get it to pass a given list.

3 Answers

Stefanie,

You're on the right track. The sum() function is what you want. There are three other parts to the puzzle:

(1) create a function

(2) give that function a parameter (remember, this goes inside the parentheses after the function name)

(3) inside the function, return the sum of the items in the list.

The key word here is return. You want to "return the sum of the numbers in the list". Turn that sentence into code.

Thank you!

def add_list(nkem):

     uchem = 0

      for juju in nkem:

            uchem += juju

      return uchem

def summarize(jude):

     uche = 0

     for ju in jude:

           uche += ju

    return "The sum of {} is {}.".format(jude, uche)
Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Effectively the challenge is asking you to recreate the built-in sum() (because it's not covered, I don't expect you to use it).

Ohhh okay =)