Verbose and flexible args and kwargs syntax

Chris Angelico rosuav at gmail.com
Mon Dec 12 11:16:08 EST 2011


On Tue, Dec 13, 2011 at 2:55 AM, Nick Dokos <nicholas.dokos at hp.com> wrote:
> Terry Reedy <tjreedy at udel.edu> wrote:
>> calculations are helped by the fact that (a+b) % c == a%c + b%c, so
>
> As long as we understand that == here does not mean "equal", only
> "congruent modulo c", e.g try a = 13, b = 12, c = 7.

This is the basis of the grade-school "casting out nines" method of
checking arithmetic. Set c=9 and you can calculate N%c fairly readily
(digit sum - I'm assuming here that the arithmetic is being done in
decimal); the sum of the remainders should equal the remainder of the
sum, but there's the inherent assumption that if the remainders sum to
something greater than nine, you digit-sum it to get the true
remainder.

(Technically the sum of the digits of a base-10 number is not the same
as that number mod 9, but if you accept that 0 == 9, it works fine.)

ChrisA



More information about the Python-list mailing list