Skip to content

Instantly share code, notes, and snippets.

@deborahtrez
Created July 29, 2021 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deborahtrez/45ab28b67a44b950bfe1006faedcaa20 to your computer and use it in GitHub Desktop.
Save deborahtrez/45ab28b67a44b950bfe1006faedcaa20 to your computer and use it in GitHub Desktop.
How to check if a number is a prime number.
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