Created
July 29, 2021 15:22
-
-
Save deborahtrez/45ab28b67a44b950bfe1006faedcaa20 to your computer and use it in GitHub Desktop.
How to check if a number is a prime number.
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
check_prime = [26, 39, 51, 53, 57, 79, 85] | |
# iterate through the check_prime list | |
for num in check_prime: | |
# search for factors, iterating through numbers ranging from 2 to the number itself | |
for i in range(2, num): | |
# number is not prime if modulo is 0 | |
if (num % i) == 0: | |
print("{} is NOT a prime number, because {} is a factor of {}".format(num, i, num)) | |
break | |
# otherwise keep checking until we've searched all possible factors, and then declare it prime | |
if i == num -1: | |
print("{} IS a prime number".format(num)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment