Created
July 4, 2012 15:58
-
-
Save joehakimrahme/3048036 to your computer and use it in GitHub Desktop.
isprime - up to sqrt()
This file contains 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 math.sqrt as sqrt | |
def prime2(n): | |
if n <= 1: | |
return False | |
# The sqrt is turned into an int() because of the | |
# deprecation warning I got for passing a float as argument | |
# to xrange() | |
for i in xrange(2, int(sqrt(n))): | |
if n % i == 0: | |
return False | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment