Finding the digit sum of a number means adding the values of all of its digits. For example, the digit sum of **123** is **1 + 2 + 3 = 6**.

A mathematical algorithm for calculating a digit sum is:

- Add the last digit of
*the number*to*the sum*.- Set
*the sum*equal to*the sum*plus the remainder of*the number*divided by 10.

- Set
- Remove the last digit of
*the number*.- Divide
*the number*by 10, rounding down.

- Divide
- Repeat the previous two steps while
*the number*is greater than zero. - Print
*the sum.*

**Drag blocks from the left to perform the algorithm, then click the "Run Code" button to see the output.**

Output | Python Code |
---|---|