problems with a for loop (noobie)
Jeremy S Lowery
jslowery at hotmail.com
Fri Jul 5 23:41:24 EDT 2002
"Charles Mantha" <charles_mantha at hotmail.com> wrote in message
news:1IsV8.42194$Fc1.850199 at wagner.videotron.net...
> Reading the Python Tutorial by Guido van Russom and there's an example
that
> I don't get, and seems to not be explained (at least not enought for me).
> The line < ... if n % x == 0: >, what does the % do?
% is the mod operator. It retrieves the remainder of the operands, from
dividing them.
>>> 4 % 2
0
4 / 2 = 2 r 0
>>> 20 % 8
4
20 / 8 = 2 r 4
Just remember 3rd grade, when you did remainders and not decimals :)
> Also I just seem to not get the logic of this program. Would be nice if
> someone would explain it to me.
if n % m == 0 then n is equally divisible by m (i.e. no remainder). like 4 %
2, 27 % 3, 121 % 11, 32 % 8
If you're into prime numbers:
http://www.utm.edu/research/primes/prove/index.html
Jeremy S Lowery
More information about the Python-list
mailing list