0
How do you understand modulo and floor division
2 ответов
+ 7
Floor division ignores any fractional result in division. The result is always rounded down to the nearest whole number.
Ex: 9 // 4 = 2. 4 goes into 9 twice, and the fractional part left over is truncated.
Modulo division gives the remainder of division.
Ex: 9 % 4 = 1. 4 goes into 9 twice, and 1 is left over, which is your result.
+ 3
How often does 5 go into 17? 3 times. 3*5 = 15, and we have 2 left over (the remainder).
17 // 5 == 3
17 % 5 == 2