1def prime(num):
2 if num>1:
3 s=int(num/2)
4 for i in range(2,s+1):
5 if num%i==0:
6 return("not prime")
7 break
8 return("prime")
9print(prime(239))
1# Time Efficient Primality Check in Python
2
3def primeCheck(n):
4 # 0, 1, even numbers greater than 2 are NOT PRIME
5 if n==1 or n==0 or (n % 2 == 0 and n > 2):
6 return "Not prime"
7 else:
8 # Not prime if divisable by another number less
9 # or equal to the square root of itself.
10 # n**(1/2) returns square root of n
11 for i in range(3, int(n**(1/2))+1, 2):
12 if n%i == 0:
13 return "Not prime"
14 return "Prime"
1until = 20
2[n for n in range(2, until) if all(n % m != 0 for m in range(2, n-1))]
1import math
2a=[i for i in range(2,int(input('prime number range'))) if 0 not in [i%n for n in range(2,int(math.sqrt(i)))]]
3print(a)
1from num_tool import is_prime
2print(is_prime(3))
3
4#returns True because 3 is a prime
1Credit to: https://www.programiz.com/python-programming/examples/prime-number
2# get all prime numbers smaller than 1000
3for num in range(0,1000):
4 if num > 1:
5 # check for factors
6 for i in range(2,num):
7 if (num % i) == 0:
8 print(num,"is not a prime number")
9 print(i,"times",num//i,"is",num)
10 break
11 else:
12 print(num,"is a prime number")
13
14 # if input number is less than
15 # or equal to 1, it is not prime
16 else:
17 print(num,"is not a prime number")