annotate python/prime.py @ 333:998d3c276b25

http://askubuntu.com/questions/168117/how-to-automatically-add-meta-tags-to-screenshot?rq=1
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 18 Jun 2013 14:44:14 -0700
parents 8593b0384d3e
children b5a59c3e4421
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
238
05728a85e19b add prime.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 #!/usr/bin/env python
05728a85e19b add prime.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2
05728a85e19b add prime.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 def prime(number):
05728a85e19b add prime.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4 half = int(number / 2)
05728a85e19b add prime.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5 for i in range(2, half):
05728a85e19b add prime.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6 if not number % i:
05728a85e19b add prime.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7 return False
05728a85e19b add prime.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8 return True
05728a85e19b add prime.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9
253
8593b0384d3e add a function for computing primes
Jeff Hammel <jhammel@mozilla.com>
parents: 238
diff changeset
10 def primes(n):
8593b0384d3e add a function for computing primes
Jeff Hammel <jhammel@mozilla.com>
parents: 238
diff changeset
11 return [i for i in range(2,n)
8593b0384d3e add a function for computing primes
Jeff Hammel <jhammel@mozilla.com>
parents: 238
diff changeset
12 if not [True for j in range(2,1 + i/2)
8593b0384d3e add a function for computing primes
Jeff Hammel <jhammel@mozilla.com>
parents: 238
diff changeset
13 if not i%j]]
8593b0384d3e add a function for computing primes
Jeff Hammel <jhammel@mozilla.com>
parents: 238
diff changeset
14
8593b0384d3e add a function for computing primes
Jeff Hammel <jhammel@mozilla.com>
parents: 238
diff changeset
15
238
05728a85e19b add prime.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
16 if __name__ == '__main__':
05728a85e19b add prime.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17 import sys
05728a85e19b add prime.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
18 for arg in sys.argv[1:]:
05728a85e19b add prime.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
19 print prime(int(arg))