Sum_digits - Unable to add correctly


It returns four instead of 11 when adding 434, or 4 + 3 + 4

It should return 11

def digit_sum(n):
    sum_digits = 0
    for c in str(n):
        sum_digits += int(c)
        return sum_digits


a function ends the moment a return keyword is reached

if a return keyword is reached in a loop, the loop will break


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.