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 trialAntony Hsu
4,377 PointsIndentation Error:
I got following error from code below. Please help.
Indentation Error: return total + num
listn = []
total = 0
def add_list(num):
for num in listn:
return total + num
def summarize(num):
for num in listn:
print ("The sum of " num "is " add_list(num))
2 Answers
Kenneth Love
Treehouse Guest TeacherYou have two for
loops that have nothing inside of them.
Also, you don't have +
between your strings in that last print()
function (and you shouldn't have a space between print
and the parentheses).
Stephen Bone
12,359 PointsHi Anthony
The return and print lines should be indented further as they are statements of their respective for loops.
Weirdly when I've tried to run it however it doesn't return the correct value and fails on the first task which is confusing as you already seem to be onto the second one.
Here's my code for the first task which will hopefully help you through the second. You create a method that takes a list as an argument, loops through each number in the list adding them together then returns the final value.
def add_list(list):
total = 0
for num in list:
total += num
return total
Hope it helps!