Skip to content

Instantly share code, notes, and snippets.

@nharrell04
Created June 22, 2013 22:29
Show Gist options
  • Save nharrell04/5842872 to your computer and use it in GitHub Desktop.
Save nharrell04/5842872 to your computer and use it in GitHub Desktop.
Determines whether a number is prime
def test_prime(x):
if x <2:
print False
elif x == 2:
print True
# maybe i'm being lazy but i couldn't think of a way to make 2 return as prime w/o doing this.
else:
for i in range(2,x-1):
y = x%i
if y > 0:
print True
# my problem is i don't want it to print "true" every time it goes through the loop; I only want it to print if every time it went through y >0
else:
print False
break
test_prime(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment