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 trialNeel Patel
5,216 PointsUnable to understand "python functions" challenge.
Hi, I am not able to understand challenge -
"Make a function named add_list that adds all of the items in a passed-in list together and returns the total. Assume the list contains only numbers. You'll probably want to use a FOR loop."
However I'm not sure what is the name of list? Can I create a new list and pass on to function?
Please explain.
4 Answers
Andreas cormack
Python Web Development Techdegree Graduate 33,011 PointsHi Neel
Basically you have got to pass a array as a argument to a function named add_list
def add_list(my_list):
total=0
for num in my_list:
total=total+num
return total
new_list=[1,2,3]
print(add_list(new_list))
try this
Kenneth Love
Treehouse Guest TeacherThe name you give to your arguments doesn't matter except to you. Make it something that makes sense to you so it'll be easier to work with.
Elizabeth Henning
4,286 PointsThis confused the crap out of me too, although I understood what you were getting at. I think it's a badly phrased question and should be rewritten.
Kenneth Love
Treehouse Guest TeacherI've updated the prompt a bit to try and make it more clear. Thanks for bringing it up!