Newbie: req for a bit of tutorial type help.
Don Tuttle
tuttledon at hotmail.com
Sun Mar 12 18:32:25 CET 2000
Hi Aesop,
Here is primes.py. I hope the fromatting survives the system
Don
---------------snip-------------------
#! /usr/bin/env python
# Print prime numbers in a given range
def main():
import sys
min, max = 2, 0x7fffffff
if sys.argv[1:]:
min = int(eval(sys.argv[1]))
if sys.argv[2:]:
max = int(eval(sys.argv[2]))
primes(min, max)
def primes(min, max):
if 2 >= min: print 2
primes = [2]
i = 3
while i <= max:
for p in primes:
if i%p == 0 or p*p > i: break
if i%p <> 0:
primes.append(i)
if i >= min: print i
i = i+2
main()
--------------snip------------------------
> Thanks for the quick response ;-) . I have the Win32 distribution, which
> does not contain the file you mentioned. Still very interested. know where
i
> can find it?
>
> TIA
>
> yours in zeros and ones.....
>
>
>
> "Moshe Zadka" <moshez at math.huji.ac.il> wrote in message
> news:Pine.GSO.4.10.10003121707240.2178-100000 at sundial...
> > For a program in Python that prints primes, look in the source
> > distribution, at the Demo/scripts/primes.py
> >
> > On Sun, 12 Mar 2000, Aesop wrote:
> >
> > > Howdy,
> > > At risk of repeating myself, i have been using python for about 2
> days
> > > now. its been at least six years since i last looked at "C" and the
old
> > > brain has been flushed and reloaded with a lot of non programming type
> > > things ;-)
> > >
> > > Am trying to write a program to calculate prime numbers. Trying to do
> this
> > > crossword type thing that is entirely mathematical in nature and i
need
> a
> > > list of prime numbers of 2 digits. Thinking this is a damned good
excuse
> for
> > > figuring out how to programme, again, I went off and downloaded
Python.
> > >
> > > Writing up a brute force type algorithm (no points for creative
thinking
> on
> > > my behalf). What i need is something that will perform divisions of
the
> > > prospective prime number, and report whether there is any "remainder".
> I.E
> > > the modulus operator of C.
> > >
> > > anyone point me to , or supply some good info for a raw recruit?
> > >
> > >
> > > Yours in zeros and ones,
> > > Ambrose. S
> > >
> > >
> > > --
> > > http://www.python.org/mailman/listinfo/python-list
> > >
> >
> > --
> > Moshe Zadka <mzadka at geocities.com>.
> > http://www.oreilly.com/news/prescod_0300.html
> >
> >
>
>
More information about the Python-list
mailing list