def digit_sum(n): result = 0 while n > 0: divided = n / 10 whole = int(divided) decimal = divided - whole result += decimal * 10 n = whole return result # TESTS # ultra simple #print(digit_sum(0)) #print(digit_sum(247)) #print(digit_sum(123456789)) #print(digit_sum(1000000000000000000001)) #print(digit_sum(00000000000000000000000)) def test_digit_sum(n, result): print("n = ", n) if digit_sum(n) != result: print("FAIL") print(result, " expected, got ", digit_sum(n)) else: print("PASS") print() if __name__ == "__main__": test_digit_sum(0, 0) test_digit_sum(247, 13) test_digit_sum(123456789, 45) test_digit_sum(1000000000000000000000000001, 2) test_digit_sum(0000000000000000000000000000000000000, 0)