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

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.