annotate python/prime.py @ 238:05728a85e19b

add prime.py
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 23 Aug 2012 15:06:23 -0700
parents
children 8593b0384d3e
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
05728a85e19b add prime.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
10 if __name__ == '__main__':
05728a85e19b add prime.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11 import sys
05728a85e19b add prime.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12 for arg in sys.argv[1:]:
05728a85e19b add prime.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13 print prime(int(arg))