2. digit_sum


#1



Can anyone please help me please? I have look at everyone else's code but it didn't help me. so please can anyone help me please>

https://www.codecademy.com/courses/python-intermediate-en-rCQKw/0/4?curriculum_id=4f89dab3d788890003000096#


Oops, try again. Your function fails on digit_sum(434). It returns None when it should return 11.
console window:
1
3
6
10
None
None


def digit_sum(n):
    total = 0
    n = str(n)
    for x in n:
        total = total + int(x)
        print total
print digit_sum(1234)


#2

your function doesn't return anything now.you are just printing total inside for loop.


#3

thanks I see what i done wrong.
it worked
thanks :smile:


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.