“Python Primes” Kode Jawaban

Daftar bilangan prima di Python

n = 20
primes = []

for i in range(2, n + 1):
	for j in range(2, int(i ** 0.5) + 1):
 		if i%j == 0:
 			break
	else:
		primes.append(i)

print(primes)
Light Leopard

adalah Python utama

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

bilangan prima di 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 Primes

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

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

Jawaban yang mirip dengan “Python Primes”

Pertanyaan yang mirip dengan “Python Primes”

Lebih banyak jawaban terkait untuk “Python Primes” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya