Skip to content

Instantly share code, notes, and snippets.

@CesarNog
CesarNog / is_prime.py
Created January 21, 2015 13:20
A prime number is a positive integer greater than 1 that has no positive divisors other than 1 and itself. (Boy, that's a mouthful.) In other words, if you want to test if a number in a variable x is prime, then no other number should go into x evenly besides 1 and x. So 2 and 5 and 11 are all prime, but 4 and 18 and 21 are not. If there is a nu…
def is_prime(x):
if x < 2:
return False
elif x == 2:
return True
else:
for n in range(2, x):
print n
if x % n == 0:
return False