jest Prime Python
def is_prime(n):
for i in range(2,int(n**0.5)+1):
if n%i==0:
return False
return True
Mouad En-naciry
def is_prime(n):
for i in range(2,int(n**0.5)+1):
if n%i==0:
return False
return True
import math
def isPrimeNumber(n):
if (n < 2):
return False;
sq = int(math.sqrt(n))
for i in range(2, sq + 1):
if (n % i == 0):
return False
return True
until = 20
[n for n in range(2, until) if all(n % m != 0 for m in range(2, n-1))]
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
a=int(input('print number:'))
for i in range(2,a):
if a%i !=0:
continue
else:
print("Its not a prime number")
break # here break is exicuted then it means else would not be exicuted.
else:
print("Its a prime number")
Credit to: https://www.programiz.com/python-programming/examples/prime-number
# get all prime numbers smaller than 1000
for num in range(0,1000):
if num > 1:
# check for factors
for i in range(2,num):
if (num % i) == 0:
print(num,"is not a prime number")
print(i,"times",num//i,"is",num)
break
else:
print(num,"is a prime number")
# if input number is less than
# or equal to 1, it is not prime
else:
print(num,"is not a prime number")