diff 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 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)