4. Digit_sum - explanation


#1

https://www.codecademy.com/courses/learn-python/lessons/practice-makes-perfect/exercises/digitsum

Please could someone explain the correct code as below (line by line):
I don’t understand what the % and // do…



def digit_sum(n):
    sum = 0
    while n > 0:
        sum += n % 10
        n = n // 10
        print n
    return sum



#2

I recommend reading up on the documentation…

https://docs.python.org/2/reference/expressions.html#binary-arithmetic-operations


#3

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