“bilangan prima python” Kode Jawaban

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

bilangan prima di 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 menghitung bilangan prima sampai numer

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

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

kode python untuk mencetak bilangan prima

# 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

bilangan prima python

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

Jawaban yang mirip dengan “bilangan prima python”

Pertanyaan yang mirip dengan “bilangan prima python”

Lebih banyak jawaban terkait untuk “bilangan prima python” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya