Mercurial > hg > config
view python/prime.py @ 802:b5a59c3e4421
more fixups, for example, but lets throw it away anyway
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Fri, 28 Oct 2016 16:57:50 -0700 |
parents | 8593b0384d3e |
children |
line wrap: on
line source
#!/usr/bin/env python """ print prime numbers for each argument given """ def prime(number): """determines if `number` is prime""" # XXX this is owefully inefficient and is written as # a (bad) example only half = int(number / 2) for i in range(2, half): if not number % i: return False return True def primes(n): return [i for i in range(2,n) if not [True for j in range(2,1 + i/2) if not i%j]] if __name__ == '__main__': import argparse parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('arg', type=int, nargs='+', help="(positive) integer to find the primes for") options = parser.parse_args() for arg in options.arg: print prime(arg)