On Tue, 15 Feb 2005 14:26:52 -0800 (PST), Da
> 
> Hi Bernard,
> 
> Another familiar example of modulo is checking to see if a number is even
> or odd:
> 
<snip lots of good stuff from danny>

Since Danny got it started with the examples, I'll give another
canonical example of the use of the modulus operator. Imagine that
we're trying to figure out what number the hour hand of a clock will
be pointing at x hours from now. If it's one o'clock right now, in 5
hours, the hour hand will be pointing at the six, and in 10 hours, it
will be pointing at the 11.

However, where will it be pointing in 16 hours? Well, in 12 hours it
will be at the one, then four more hours later it will be pointing at
the five. This can be represented as:

1 + (16 % 12) = 1 + 4 = 5

In general, the hour at some point in the future will be:

(start time) + (hours in the future % 12)

Peace
Bill Mill
bill.mill at gmail.com
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to