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
Elizabeth McInerney
3,175 PointsPython Basics Functions Challenge Task 1
I am having trouble with the following code. It looks like the problem is with the print statement. I will just retype it here since I can't figure out how to cut and paste it:
list = [1,2,3]
def add_list(arg):
total = 0
for item in arg:
total = total + arg[item-1]
return total
def summarize(arg):
print("The sum of {} is {}").format(arg, add_list(arg))
summarize(list)
Elizabeth McInerney
3,175 PointsSorry about that, it looks like Treehouse did keep the formatting I used when I typed in my code it. Also, take out the end parenthesis before the .format. It is crashing on the last line.
Elizabeth McInerney
3,175 PointsMichael, Should you have an end parenthesis following .format(list? I think you need to take that out, and then add another one after total).
2 Answers
Michael Pastran
4,727 Pointshey, yeah i got it working. this is the code i used to solve mine tho
list = [1,2,3]
def add_list(list):
total = 0
for i in list:
total += i
return total
def summarize(total):
return ("The sum of {} is {}".format(list,total))
Elizabeth McInerney
3,175 PointsI got it to work with:
def summarize(list): return ("the sum of {} is {}".format(list, add_list(list)))
Michael Pastran
4,727 PointsMichael Pastran
4,727 Pointshey elizabeth , im actually stuck in the same problem right now. i cant seem to find it.
this is the code i have so far. in the instructions it doesnt say anything about a second function. but in the code box it says there should be two.