ist 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
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
def prime_number(n):
c = 0
for x in range(2, n):
if n % x == 0:
c = c + 1
return c
n = int(input("Enter a number = "))
if prime_number(n) == 0:
print("Prime number.")
else:
print("Not prime number.")
def isPrime(n):
if n<2: #1, 0 and all negative numbers are not prime
return False
elif n==2: #2 is prime but cannot be calculated with the formula below becuase of the range function
return True
else:
for i in range(2, n):
if (n % i) == 0: #if you can precisely divide a number by another number, it is not prime
return False
return True #if the progam dont return False and arrives here, it means it has checked all the numebrs smaller than n and nono of them divides n. So n is prime
from math import sqrt, floor;
def is_prime(num):
if num < 2: return False;
if num == 2: return True;
if num % 2 == 0: return False;
for i in range(3,floor(sqrt(num))+1,2):
if num % i == 0: return False;
return True;