Sum_digits - Unable to add correctly


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/0/4?curriculum_id=4f89dab3d788890003000096


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


#2

a function ends the moment a return keyword is reached

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


#3

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