“bilangan prima menggunakan python” Kode Jawaban

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

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

Program Python bilangan prima

#prime number verification program
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")#this is out of the for loop suite.
        
Gr@Y_orphan_ViLL@in##

bilangan prima di Python

# This shows how we can use for + else using a break in between

for x in range(1,101):
# if you want to find whether a user input is a prime number
# use the following insted of the first for loop
# x = int(input("Type a number: "))
    for i in range(2, x):
        if x % i == 0:
            print(x, "is not a prime number.")
            break
    else:
        print(x, "is a prime number.")

# This will print all the numbers from 1-100,
# in the same line will print whether it is a prime or not

# if you use the user input method
# when you type 9, the output will be:
# 9 is not a prime number.

# when you type 7, the output will be:
# 7 is a prime number.
Rajitha Amarasinghe

bilangan prima menggunakan python

def prime(n):
    if n>1:
        if n==2 or n==3:
                print("it is a prime number")
        for i in range(2,int(n/2)+1):
            if n%i==0:
                print("it is not a prime number")
                break
            else:
                print("it's a prime number")
                break
    else:
        print("it is not a prime number")

    
Spotless Salmon

bilangan prima di Python

a=int(input('number:'))
if a % 2 ==0 and a / 2 <= 2:
    print('composite')
elif a % 3 == 0 and a/3 <= 2:
    print('composit')
elif a % 5 == 0 and a/5 <= 2 :
    print('composit')
elif a % 7 == 0 and a/7 <= 2:
    print('composit')
else:
    print('prime')
________________________________________________________________________________
Gr@Y_orphan_ViLL@in##

Jawaban yang mirip dengan “bilangan prima menggunakan python”

Pertanyaan yang mirip dengan “bilangan prima menggunakan python”

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

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya