Trigety - 1 year ago 87

Python Question

I have been trying to understand the "%" (Percent), but i just cant get this figured.

If 16 % 2 remainder is 0

(16/2 leaves 0 remainders left because the 2 can be devided fully into the number 16)

And 15 % 2 remainder is 1

(15/2 leaves 1 remainder because 2 can not be devided up into 15 and leaves a remainder of 1 left)

All is good until now...

Now, what about if you turned the numbers around.

2 % 16 would have no remainders if im right now that i can not devide 15 with 2

And what would the output be with another number like 15.

2 % 15 would also leave no remainder cause the number 15 can not be devided by 2 so it also leaves it to a 0?

Now i dont really know if that is how this works?

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

2 % 16 is 2 because 2 divided by 16 is 0 with remainder 2.

2 % 15 is also 2, for the same reason.

Looking at it from the other side:

15 / 2 = 7 remainder 1, because 7 * 2 + 1 = 15.

2 / 16 = 0 remainder 2, because 0 * 16 + 2 = 2.