tags:

views:

117

answers:

6

I'm messing with the modulo operation in python and I understand that it will spit back what the remainder is.

But what if the first number is smaller than the second?

for instance

2 % 5 the answer is 2.

How does that work?

2/5 = .4!

+5  A: 

five goes into 2 zero times.

5*0 = 0

2-0 = 2.

the answer is 2

MedicineMan
+1  A: 

You can think of it as 2 / 5 = 0 with a remainder of 2 of 5.

akf
A: 

a % b = a if a << b

RC
I think you mean if `0 < a < b` ... if `a` is negative then you're in trouble.
Matthew Scharley
nice catch I should have been more precise.
RC
+1  A: 

2 divided by 5 (integer division) is 0 with a remainder of 2.

qpingu
+6  A: 

Does this help

22  % 5 = 2 
17  % 5 = 2 
12  % 5 = 2 
7   % 5 = 2 
2   % 5 = 2

Maybe this

22 / 5 = 4 + 2/5
17 / 5 = 3 + 2/5
12 / 5 = 2 + 2/5
7  / 5 = 1 + 2/5
2  / 5 = 0 + 2/5
jrhicks
A: 

2 = 0 x 5 + 2

Pascal Thivent