“Primzahlen Python” Code-Antworten

Primzahl in 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

Primzahlen in 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 berechnen Primzahlen bis zur Numer

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

Primzahl in 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

Python -Code zum Drucken von Primzahlen

# 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

Primzahlen Python

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

Ähnliche Antworten wie “Primzahlen Python”

Fragen ähnlich wie “Primzahlen Python”

Weitere verwandte Antworten zu “Primzahlen Python” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen