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

Jameson Remick
Jameson Remick
565 Points

Am I supposed to do this whole thing with just one function? And without actually making a list?

How can I make a list and add up the numbers in one function? Wouldn't I have to start with a list, define a function to add numbers to the list, and then define another function to add the numbers in the list up? Or am I missing something/overthinking this?

functions.py
def add_list(num)

1 Answer

kirkbyo
kirkbyo
15,791 Points

Hi Jameson,

You might be a tad overthinking this. The question will give you a list when you check your code so you don't have to worry about the list. The challenge will give you a list looking like this

[1, 2, 3, 4, 5, 6]

After you created your add_list function and created an argument you will want to create a for loop to loop through each number and then add it to a sum variable (or any variable name of your chosen). Here is how I accomplished this.

def add_list(x):
  sum = 0
  for nums in x:
    sum += nums

  return sum

I hope this helped. If you have any other question don't hesitate to ask.

Ozzie

Jameson Remick
Jameson Remick
565 Points

Thanks! That'll do it. I just wish the video went a little deeper and the instructions for this particular challenge were a bit more specific. Otherwise, I'm having a fantastic time with this and I greatly appreciate your help.