4. digit_sum


#1

def digit_sum(n):
    result = 0
    i = 1
    while i < 4:
        result += n % 10
        n = n // 10
        i += 1
    print result

#2

Are you asking a question or posting the correct code?


#3

umm if you are having an error it is probably because you are causing the loop to terminate prematurely. To fix that, you will probably want to use a different method of going through n instead of terminating the while loop with a magic number.


#4

How can you fix that the number of digits in n is going to be 4?