Modulus python section for loops after while loops
in modulus i do understand 10 % 2 = 0 but why is 2% 10 = 2?
2 answers ( 0 marked as helpful)
Hey Wahab,
Thank you for your question!
Before explaining the result of 2%10, let us take a couple other examples.
Consider 10%4. In order to obtain the answer, we first express 10 as follows:
10 = 2*4 + 2
The 2 in the end is what "remains" to be added to 2*4 in order to obtain 10.
Now consider 10%2. We can express 10 as
10 = 5*2 + 0.
Therefore, 0 is our remainder.
Lastly, we look at 2%10. There is no whole number which multiplies 10 to give 2. The only way in which we can express 2 is the following:
2 = 0*10 + 2
Therefore, 2 is the remainder.
Similarly, 3%10 = 3, 4%10 = 4, 5%20 = 5 and so on..
Hope this explains it! Keep up the good work!
Kind regards,
365 Hristina
Very helpful, Hristina!