Last active
December 21, 2015 04:49
-
-
Save iambibhas/6252848 to your computer and use it in GitHub Desktop.
Checks if the given number is prime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import math | |
def is_prime(number): | |
if number <= 1: | |
return False | |
if number == 2: | |
return True | |
if number % 2 == 0: | |
return False | |
for current in range(3, int(math.sqrt(number) + 1), 2): | |
if number % current == 0: | |
print "Divisible by ", current | |
return False | |
return True | |
if __name__ == "__main__": | |
if len(sys.argv) >= 2: | |
print is_prime(int(sys.argv[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment