Two operations peel digits off a number:
n % 10gives the last digitMath.floor(n / 10)(orn // 10in Python) removes the last digit
Repeat both until n becomes 0:
total = 0
while n > 0:
total += n % 10
n //= 10
This digit-peeling loop is the backbone of the next several lessons: reversing, palindromes, Armstrong numbers and digital roots.