“Prime números python” Código de respuesta

Prime número en Python

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.")
Excited Earthworm

Primes en 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

Python calcule números primos hasta el número

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

Prime número en 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

Código de Python para imprimir números primos

# Thanks to https://www.codegrepper.com/profile/farid
# Just tune his answer into easy to use function

def prime_numbers(start_num, end_num):
    for number in range(start_num , end_num + 1):
        is_prime = True
        for counter in range(2,number):
            value = number % counter
            if value == 0:
                is_prime = False
                break
        if is_prime == True:
            print(number)
mathiasgodwin

Prime números python

def is_prime(n):
  for i in range(2,n):
    if (n%i) == 0:
      return False
  return True
Atanas Atanasov

Respuestas similares a “Prime números python”

Preguntas similares a “Prime números python”

Más respuestas relacionadas con “Prime números python” en Python

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código