Mercurial > hg > config
changeset 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 | bea4dd61ae45 |
children | 70e9f82c2443 |
files | python/prime.py |
diffstat | 1 files changed, 15 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/python/prime.py Fri Oct 28 16:14:10 2016 -0700 +++ b/python/prime.py Fri Oct 28 16:57:50 2016 -0700 @@ -1,6 +1,14 @@ #!/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: @@ -14,6 +22,10 @@ if __name__ == '__main__': - import sys - for arg in sys.argv[1:]: - print prime(int(arg)) + 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)