"lostinpython" <[EMAIL PROTECTED]> writes: > I'm having trouble writing a program that figures out a prime number. > Does anyone have an idea on how to write it? All I know is that n > 2 > is prim if no number between 2 and sqrt of n (inclusivly) evenly > divides n.
How about this (untested): import sys import subprocess primes = subprocess.Popen(["primes", sys.argv[1], sys.argv[1]], stdout=subprocess.PIPE).stdout.readlines() if primes: print sys.argv[1], "prime" else: print sys.argv[1], "not prime" Seriously, this sounds like a homework assignment. Google for "sieve of eratosthenes". The BSD "primes" program I used in the above is an implementation of that in C. If it isn't a homework assignment, and you're honestly in such, then you should know there's been a lot of research in this area, because primes are important in cryptographic applications. Once again, google is a good place to start on looking for recent research on the subject. <mike -- Mike Meyer <[EMAIL PROTECTED]> http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list