Use richer assertions in test_mailbox (for better failure messages).
[python.git] / Demo / scripts / primes.py
blob2bf5ba2ed56ed95d33c714a233a19a4f8271e6cc
1 #! /usr/bin/env python
3 # Print prime numbers in a given range
5 def primes(min, max):
6 if max >= 2 >= min:
7 print 2
8 primes = [2]
9 i = 3
10 while i <= max:
11 for p in primes:
12 if i % p == 0 or p*p > i:
13 break
14 if i % p != 0:
15 primes.append(i)
16 if i >= min:
17 print i
18 i += 2
20 def main():
21 import sys
22 min, max = 2, 0x7fffffff
23 if sys.argv[1:]:
24 min = int(sys.argv[1])
25 if sys.argv[2:]:
26 max = int(sys.argv[2])
27 primes(min, max)
29 if __name__ == "__main__":
30 main()