repo.or.cz
/
python
/
dscho.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
This commit was manufactured by cvs2svn to create tag 'r22a4-fork'.
[python/dscho.git]
/
Demo
/
scripts
/
primes.py
blob
477c57bda9f9c2b7727f9fe5cfbaa4a58c3aa2a0
1
#! /usr/bin/env python
2
3
# Print prime numbers in a given range
4
5
def
main
():
6
import
sys
7
min
,
max
=
2
,
0x7fffffff
8
if
sys
.
argv
[
1
:]:
9
min
=
int
(
eval
(
sys
.
argv
[
1
]))
10
if
sys
.
argv
[
2
:]:
11
max
=
int
(
eval
(
sys
.
argv
[
2
]))
12
primes
(
min
,
max
)
13
14
def
primes
(
min
,
max
):
15
if
2
>=
min
:
print
2
16
primes
= [
2
]
17
i
=
3
18
while
i
<=
max
:
19
for
p
in
primes
:
20
if
i
%
p
==
0
or
p
*
p
>
i
:
break
21
if
i
%
p
<>
0
:
22
primes
.
append
(
i
)
23
if
i
>=
min
:
print
i
24
i
=
i
+
2
25
26
main
()