0
Can someone please explain this
Can someone please explain to me how modulo (%) works? Thanks
3 Answers
+ 5
Check out this thread. I give an answer there on this, including negative cases:
https://www.sololearn.com/discuss/272747/?ref=app
+ 1
It gives remainder after it is divided as many times as it can.
4%2...... 0
2, 4 - 0 left over
10%2.... 0
2,4,6,8,10 - 0 left over
10%3.... 1
3,6,9 - 1 left over
15%4.... 3
4,8,12 - 3 left over
Common use is to check for even or odd numbers.
if number%2 == 0:
Number is even
if number%2 != 0:
Number is odd
0
it returns the reminder value of division as:
3%2=1
- 3/2=1.5
so the float no. is 0.5 multiply it to 2 not 3 so it equal 1
so 3%2=1
- 10 %6=4
10/6=1.6666666666667
0.6666666666667 Ă 6=4
10%6=4