Skip to content

Instantly share code, notes, and snippets.

@Fergmux
Created February 11, 2014 16:28
Show Gist options
  • Save Fergmux/8938316 to your computer and use it in GitHub Desktop.
Save Fergmux/8938316 to your computer and use it in GitHub Desktop.
def is_prime(x):
n = range(2, abs(x))
for i in n:
if abs(x) % i == 0:
return False
else:
return True
@danmux
Copy link

danmux commented Feb 11, 2014


def is_prime(x):
    n = range(2, 1 + abs(x)/2)
    for i in n:
        if x % i == 0:
            return False

    return True

print 1, is_prime(1)
print 2, is_prime(2)
print 3, is_prime(3)
print 4, is_prime(4)
print 5, is_prime(5)
print 6, is_prime(6)
print 7, is_prime(7)
print -1, is_prime(-1)
print -2, is_prime(-2)
print -3, is_prime(-3)
print -17, is_prime(-17)
print 17, is_prime(17)
print 10, is_prime(10)
print 11, is_prime(11)
print -18, is_prime(-18)
print -16568, is_prime(-16568)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment