Adam Christopher Martin wrote:I understand completely about what modulus does vis-à-vis fetching the remainder, but I don't understand why using the modulus operator gets you each digit individually?
and why does number have to be reassigned as number / 10?
Apologies if this is stupid - I just can't wrap my head around it right now!
Hello Adam Christopher Martin.
First of all there's not such a stupid questions in this forum. We are all here to learn. So don't worry about it.
Solving problems like this, the best approach is to get pencil and piece of paper - so you could write it down and everything could become clear.
Let's take a number, for instance 123
number = 123
1st round
Print (123 % 10) = 3
number = 123 / 10 = 12 (since it is integer you get whole number by dividing it, not a float 12.3)
2nd round
Print (12 % 10) = 2
number = 12 / 10 = 1
3rd round
Print (1 % 10) = 1
number = 1 / 10 = 0
end, since
Did it become more clear?