Last active
August 29, 2015 14:23
-
-
Save jonathanpike/3bd80e30a750708bed97 to your computer and use it in GitHub Desktop.
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
# from http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html | |
def is_prime(num): | |
print "Checking if %d is Prime" % num | |
numrange = [x for x in range(2,num)] | |
count = 0 | |
for i in numrange: | |
if num % i != 0: | |
count = count | |
elif num % i == 0: | |
count += 1 | |
if count == 0: | |
print "%d is Prime" % num | |
else: | |
print "%d is not Prime" % num | |
# Infinite loop so you can keep entering numbers | |
while 1==1: | |
is_prime(int(raw_input("Enter a number (ctrl+c to quit): "))) | |
""" This is an automated test using the first 168 Prime numbers, with a few other numbers thrown in for fun. The only difference is that the function loops through the list, whereas the challenge function asks the user for input. """ | |
def is_prime_TEST(num): | |
for i in num: | |
print "Checking if %d is Prime" % i | |
count = 0 | |
numrange = [x for x in range(2,i)] | |
if i == 2: | |
print "The number is Prime" | |
for z in numrange: | |
if i % z != 0: | |
count = count | |
else: | |
count += 1 | |
if count == 0: | |
print "%d is Prime" % i | |
else: | |
print "%d is not Prime" % i | |
""" checkTEST = [2, 3, 5, 6, 7, 10, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 80, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 228, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 390, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 570, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 742, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 828, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 920, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 998] """ | |
# is_prime_TEST(checkTEST) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment