“Python Primzahl” Code-Antworten

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

ist 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 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

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

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 Primzahl

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

Ähnliche Antworten wie “Python Primzahl”

Fragen ähnlich wie “Python Primzahl”

Weitere verwandte Antworten zu “Python Primzahl” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen