4. digit_sum



Error Message: Your function fails on digit_sum(434). It returns 4 when it should return 11.


def digit_sum(n):
    num_str = str(n)
    for i in range(len(num_str)):
        total = 0
        total += int(num_str[i])
    return total


did you check existing topics? I answered the exact same question today:

the code is too shocking similiar, or is that just me?


Thank you for the link. But, I still manage to get the error somehow. Just that can’t work on the solution for return Total


Well, anyhow got it working now. Thanks a lot for the hint!