def digit_sum(n): result = 0 i = 1 while i < 4: result += n % 10 n = n // 10 i += 1 print result
Are you asking a question or posting the correct code?
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.
How can you fix that the number of digits in
n is going to be 4?