“Numéro primaire à l'aide de Python” Réponses codées

Prime dans 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

Numéro premier dans 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

Programme Prime Number Python

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

Numéro premier dans 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

Numéro primaire à l'aide de 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

Numéro premier dans 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##

Réponses similaires à “Numéro primaire à l'aide de Python”

Questions similaires à “Numéro primaire à l'aide de Python”

Plus de réponses similaires à “Numéro primaire à l'aide de Python” dans Python

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code