“Numéro primaire Python” Réponses codées

est 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

est Prime Python

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
Sore Stork

Python calcule les nombres premiers jusqu'à ce que

until = 20
[n for n in range(2, until) if all(n % m != 0 for m in range(2, n-1))]
Upset Unicorn

Prime dans Python

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
Old-fashioned Ostrich

Numéro premier dans Python

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")
Impossible Impala

Numéro primaire Python

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")
Confused Capuchin

Réponses similaires à “Numéro primaire Python”

Questions similaires à “Numéro primaire Python”

Plus de réponses similaires à “Numéro primaire Python” dans Python

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code