Skip to content

Instantly share code, notes, and snippets.

@rchowe
Last active August 29, 2015 14:15
Show Gist options
  • Select an option

  • Save rchowe/5b9103779ac33dcdaade to your computer and use it in GitHub Desktop.

Select an option

Save rchowe/5b9103779ac33dcdaade to your computer and use it in GitHub Desktop.
Check primes
#!/usr/bin/env python
#
# check_prime.py
# Check if a number (given by the first argument) is prime.
#
import sys
import math
# Die if there is no first argument.
if len(sys.argv) < 2:
print('USAGE: {} N'.format(sys.argv[0]))
sys.exit(1)
N = int(sys.argv[1])
for i in range(2, int(math.sqrt(N))):
if N % i == 0: break
else:
print(N)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment