]> granicus.if.org Git - python/commitdiff
Update primes script.
authorGeorg Brandl <georg@python.org>
Sun, 11 Oct 2009 08:48:28 +0000 (08:48 +0000)
committerGeorg Brandl <georg@python.org>
Sun, 11 Oct 2009 08:48:28 +0000 (08:48 +0000)
Demo/scripts/README
Demo/scripts/primes.py

index 8e1b26f42f7d7a6d5b3a34f9ec6018df4f0bd4d8..434c09b3d02c005a2bb6ca2bee1985938ae104b1 100644 (file)
@@ -2,7 +2,7 @@ This directory contains a collection of executable Python scripts.
 
 See also the Tools/scripts directory!
 
-beer.py                        Print the classic 'bottles of beer' list.
+beer.py                        Print the classic 'bottles of beer' list
 eqfix.py               Fix .py files to use the correct equality test operator
 fact.py                        Factorize numbers
 find-uname.py          Search for Unicode characters using regexps
index 5935a3c84a82d83a2789cdf1c2ff40d3a2c7a5d1..eeb14eec47ec26470130a9ec19719cc8fcaeddd1 100755 (executable)
@@ -2,26 +2,29 @@
 
 # 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
+    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:
+            if i % p == 0 or p*p > i:
+                break
+        if i % p != 0:
             primes.append(i)
-            if i >= min: print i
-        i = i+2
+            if i >= min:
+                print i
+        i += 2
+
+def main():
+    import sys
+    min, max = 2, 0x7fffffff
+    if sys.argv[1:]:
+        min = int(sys.argv[1])
+        if sys.argv[2:]:
+            max = int(sys.argv[2])
+    primes(min, max)
 
 if __name__ == "__main__":
     main()