Created
June 22, 2013 22:29
-
-
Save nharrell04/5842872 to your computer and use it in GitHub Desktop.
Determines whether a number is prime
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
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