I have been tinkering with this code for hours. Yet, this code returns a different answer. Can anyone address what is wrong in the following code?
digit_sum returns wrong answer
input 123 gives 9 as output which is wrong.
def digit_sum(n): rem = n % 10 s = 0 while True: s += rem n //= 10 if n==0: break return s