Sum of Digits (FLOW006) : Solution with hints

Hint 1:

Click to view

What does N \bmod 10 give you?
Try with numbers 45, 500.

Hint 2:

Click to view

It gives you the right-most digit in the decimal representation of the number.

Hint 3:

Click to view

What does N // 10 do?
Try with numbers 45, 500.

Hint 4:

Click to view

Chops off the right-most digit in the decimal representation of the number.

Hint 5:

Click to view

Now we have way to get current digit, and chop it off.
How long do we need to repeat this process?

Hint 6:

Click to view

Until we get the number 0.

Hint 7 (full solution):

Click to view

We can use a while loop to keep going until the current number is 0, and store the sum in another variable, where we add each digit.

//