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 trialMilagros Roman
1,228 PointsI'm tired, I want to advance and it gives error and I am stop on the workplace, I don't receive error for this code
add_list = list()
summarized = 0
def adding_list(num):
add_list.append(num)
for num in range(4):
adding_list(num)
summarized = summarized + add_list[num]
print(summarized)
print(add_list)
# add_list([1, 2, 3]) should return 6
# summarize([1, 2, 3]) should return "The sum of [1, 2, 3] is 6."
# Note: both functions will only take *one* argument each.
add_list = list()
summarized = 0
def adding_list(num):
add_list.append(num)
for num in range(4):
adding_list(num)
summarized = summarized + add_list[num]
print(summarized)
print(add_list)
[EDIT: formatting updated]
1 Answer
Andrei Fecioru
15,059 PointsHi,
The exercise requires that you make a function called add_list
. Instead you've created a variable add_list
and you assigned an empty list to it. When you do add_list = list()
you assign an empty list to a new variable called add_list
.
Since the add_list
points to an empty list and not a function that can be invoked, the automatic exercise checker will issue an error (it will try to actually invoke the empty list as a function).
Try to read carefully the exercise and do what it requires. In this case, you need to implement a function called add_list
. So, in your code you should have something like:
def add_list(a_list):
# do something here with the input list
Hope this helps.