+ 1

Why is 1 % 2 = 1? I understand that 13 % 4 = 1 because 1 is the remainder of 13 / 4, but I don't see how the first modulus works. Can someone explain this please?

2nd Oct 2016, 7:49 PM
method
method - avatar
6 Respuestas
+ 3
13 // 4 = 3 and 13 % 4 = 1 because 13 = 3*4 + 1 1 // 2 = 0 and 1 % 2 = 1 because 1 = 0*2 + 1 so I see no problem...
2nd Oct 2016, 8:15 PM
Amarie
+ 2
Modulus continues up until the remaining value is less than what you're dividing by. 1%2 isn't even performed because 1 starts out less than 2, therefore the remainder is 1.
3rd Oct 2016, 4:01 AM
Kirk Schafer
Kirk Schafer - avatar
0
but 1//2 isnt 1/2 or 0,5? y dont understand
3rd Oct 2016, 3:47 AM
Benjamin Parga
Benjamin Parga - avatar
0
so... for example, 3//2 = 1?
3rd Oct 2016, 4:16 AM
Benjamin Parga
Benjamin Parga - avatar
0
Thank you Amarie and Kirk for taking the time to explain that.
3rd Oct 2016, 4:18 AM
method
method - avatar
0
print(1//2) = 0 results in integer result print(1/2) = 0.5 results in decimal result print(1%2) = 1 results in remainder
3rd Oct 2016, 2:04 PM
Lunu'anaki
Lunu'anaki - avatar