“PRIMES PYTHON” Kod odpowiedzi

jest 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 oblicz liczby pierwszorzędne, aż do numeru

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

Programy w Pythonie

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

PRIMES PYTYHON

def is_prime(n):
    if n in (2, 3):
        return True
    if n <= 1 or not (n%6==1 or n%6==5):
        return False
    a, b= 5, 2
    while a <= n**0.5:
        if not n%a:
            return False
        a, b = a+b, 6-b
    return True
# this method is much faster than checking every number because it uses the fact
# that every prime is either 1 above or 1 below a multiple of 6
# and that if a number has no prime factors, it has no factors at all
fmoeran

główny numer w 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 PYTHON

import math

def main():
    count = 3
    
    while True:
        isprime = True
        
        for x in range(2, int(math.sqrt(count) + 1)):
            if count % x == 0: 
                isprime = False
                break
        
        if isprime:
            print count
        
        count += 1
Thankful Tuatara

Odpowiedzi podobne do “PRIMES PYTHON”

Pytania podobne do “PRIMES PYTHON”

Więcej pokrewnych odpowiedzi na “PRIMES PYTHON” w Python

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu