Digit_sum


#1




The following code works great on my pc but i got an error in the site. I'm using python 2.7.


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


#2

Got it, i should use return instead of print.


#3

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