xxxxxxxxxx
def find_primes(n):
primes = []
for num in range(2, n + 1):
prime = True
for i in range(2, num):
if (num % i) == 0:
prime = False
break
if prime:
primes.append(num)
return primes
# Output primes between 2 and 100
primes_between_2_and_100 = find_primes(100)
primes_between_2_and_100
xxxxxxxxxx
from math import sqrt
for i in range(2, int(sqrt(num)) + 1):
if num % i == 0:
print("Not Prime")
break
print("Prime")
# Note: Use this if your num is big (ex. 10000 or bigger) for efficiency
# The result is still the same if the num is smaller
xxxxxxxxxx
def prime_checker(number):
is_prime = True #use a bool to flag prime number
for i in range(2, number):# starts at 2 and loops until the range of number
if number % i == 0:# if is divisible not a prime
is_prime = False
if is_prime == True:
print(f"{number} is a prime number")
else:
print(f"{number} is a not a prime number.")
n = int(input("Check this number: "))#check a number for prime
prime_checker(number=n)#call the function
xxxxxxxxxx
#Good way to check if a number is prime or not
"""Number_Check is the number that you want to see if it is prime or not
For example 3 would return true because it is prime while 10 would return false
because it isn't prime"""
def check_prime(Number_Check):
isprime = True
for i in range(2, Number_Check - 1):
if int(Number_Check / i) == Number_Check / i:
isprime = False
return isprime
xxxxxxxxxx
import math
def main():
count = 3
while True:
isprime = True
for x in range(2, int(math.sqrt(count) + 1)):
if count % x == 0:
isprime = False
break
if isprime:
print count
count += 1