def digit_sum(n):
print "we are in"
total = 0
for digit in str(n):
total += int(digit)
return "why it does return None"

Prints out "Your function fails on digit_sum(434). It returns None when it should return 11."

I dont get the problem. Can someone help?


Why do you return a statement instead of solution? Your code fails because your function doesn't return correct value



you have to indent the function body.

def my_func:
    print "this line starts with 4 spaces"

I think they changed the function to return a string literal after reading the error to make sure it returns something.


It is indented, just copied like this


I wanted to see if it does return anything

And i fixed it with:
def digit_sum(n):total = 0
for digit in str(n):
total = total + int(digit)
return total


So does it work now?


You can leave

it is okey.
I've tested your code and all I had to do was to change

onto return total

Also, to present your code properly indented use three backquotes before and three backquotes after your code.
Backqoute is this


Yep, you where right :slightly_smiling: I was little confused by that.


Awesome thanks :smiley:


Another simple alternative.