[Tutor] HOW DO I PYTHONIZE A BASICALLY BASIC PROGRAM?
Kent Johnson
kent37 at tds.net
Tue Jan 13 12:38:41 CET 2009
On Mon, Jan 12, 2009 at 9:20 PM, bob gailer <bgailer at gmail.com> wrote:
> for natnum in range(1000):
> if not (natnum % 3 or natnum % 5): # adds 1 if divisible by 3 and/or 5
> cume += 1
> if not natnum % 15: # remove one of the ones if divisible by 15
> cume -= 1
This subtraction is not needed because the multiples of 15 are not
double-counted. The 'or' condition counts multiples of 15 just once.
Kent
More information about the Tutor
mailing list