[Tutor] HOW DO I PYTHONIZE A BASICALLY BASIC PROGRAM?
WM.
wferguson1 at socal.rr.com
Mon Jan 12 23:23:41 CET 2009
# The natural numbers(natnum), under 1000, divisible by 3 or by 5 are to
be added together.
natnum = 0
num3 = 0
num5 = 0
cume = 0
# The 'and' is the 15 filter; the 'or' is the 3 or 5 filter.
while natnum <= 999:
num3 = natnum/3
num5 = natnum/5
if natnum - (num3 * 3) == 0 and natnum - (num5 * 5) == 0:
cume = cume + natnum
elif natnum - (num3 * 3) == 0 or natnum - (num5 * 5) == 0:
if natnum - (num3 * 3) == 0:
cume = cume + natnum
elif natnum - (num5 * 5) == 0:
cume = cume + natnum
natnum = natnum + 1
print cume
This problem was kicked around last month and I did not understand any
of the scripts. So I tried to recall the BASIC ifs and loops. The
project euler guys say it works, but how might it be made more Pythonic?
More information about the Tutor
mailing list