DIV and MOD

Matt Gerrans mgerrans at mindspring.com
Mon Jul 29 11:54:05 EDT 2002


> don't know how to do that. % does not work as expected (in this context)

Why do you say that?   / and % give exactly the results I'd expect:

>>> for i in range(10): print '%d / %d is %d; %d %% %d is %d' %
(i,3,i/3,i,3,i%3)

0 / 3 is 0; 0 % 3 is 0
1 / 3 is 0; 1 % 3 is 1
2 / 3 is 0; 2 % 3 is 2
3 / 3 is 1; 3 % 3 is 0
4 / 3 is 1; 4 % 3 is 1
5 / 3 is 1; 5 % 3 is 2
6 / 3 is 2; 6 % 3 is 0
7 / 3 is 2; 7 % 3 is 1
8 / 3 is 2; 8 % 3 is 2
9 / 3 is 3; 9 % 3 is 0






More information about the Python-list mailing list