Practice makes perfect Exercise digit_sum


#1

Hi! Please, how can I prove this solution? I create a variable x = 1234 but don’t work!! Thanks!!

def digit_sum(x):
    total = 0
    while x > 0:
        total += x % 10
        x = x // 10
        print x
    return total

#2

That is why there is a simple rule… Don’t use code you didnt’ create if you don’t understand how it works.


#3

Thanks!..but don’t help, professor.


#4

Not sure what the problem is on your end. The code looks and works fine. Have you tried calling the function?