Welcome to the Treehouse Community
Looking to learn something new?
Make a function named add_list that takes a list. The function should then add all of the items in the list together and return the total. Assume the list contains only numbers. You'll probably want to use a for loop. You will not need to use input().
I can't understand what wrong with my code:
def add_list([1,2,3]) for item in add_list: print (item+item+item)
[MOD: added ```python markdown formattting -cf]
Chris FreemanTreehouse Moderator 67,989 Points
There are 6 issues with your code:
def add_list(a_list): # <--#1 missing colon at end of line. #2 provide parameter instead of hardcoded value total = 0 # <-- need to initiate total before loop for item in a_list: # <-- operate on parameter instead of function name total = total + item # <-- need to accumulate total as for loop runs return total # <-- need a return statement to send value back. A print is not sufficient