+ 2
Question About remainder
Could anyone explain me how to calculate this ? 7%(5//2) I understand the part that 5//2 = 2 Then 7%2 should be 0 though But the answer was 1 , I’m so confused now
4 Respostas
+ 5
% sign represents the modulus function.It calculates the remainder.
So when 7 is devided by 2, a remainder of 1 comes as 7 is an odd no.
Thus 7%2=1and not 0.
Hope this helps you,Midori.
+ 5
https://en.m.wikipedia.org/wiki/Modulo_operation
Modulo is integer division.
An example:
2018%5 = 5*403 + 3
+ 3
a%b is something like a - a//b * b
so 7 % 2 = 7 - 7//2 * 2
7 - 3 * 2
7 - 6 = 1
or you can subtract b from a while a > b
+ 2
thanks for explaining , but i just started it , i think i still got a lot to catch up , ill look into it more :) thanks!