0
Please can someone explain this % to me? I don't understand how its calculated.
Calculation
3 Respuestas
+ 1
if you have 2 integers - say x and y - x % y is the remainder when you divide x by y.
So 19 % 3 = 1, because when you divide 19 by 3 you get 6 remainder 1.
24 % 4 = 0, because 24 divided by 4 is 6 with 0 remaining.
The companion operator is integer division, written '//'.
So 19 // 3 = 6 (we disregard the remainder.
+ 4
Basically, it returns a remainder of the division. Somewhat easily understood for positive numbers, as 12 % 5 = 2 (12/5 = 2 and 2 as a remainder), it gets tricky when negatives are concerned:
12 % 5 = 2 (2*5 +2)
12 % -5 = -3 (3*-5 -3)
-12 % 5 = 3 (-3*5 +3)
-12 % -5 = -2 (-2*-5 -2)
+ 2
https://code.sololearn.com/W7X805sc4DPC/?ref=app
it's the modulus operator.