+ 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?
6 Réponses
+ 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...
+ 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.
0
but 1//2 isnt 1/2 or 0,5? y dont understand
0
so... for example, 3//2 = 1?
0
Thank you Amarie and Kirk for taking the time to explain that.
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