“Numéro premier dans Python” Réponses codées

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

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

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 premier dans Python

start_num , end_num = input("enter 2 number sepreted by ,:").split(",")
start_num , end_num = int(start_num) , int(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)
Fawlid

Numéro premier dans Python

a=int(input("Enter number: "))
k=0
for i in range(2,a//2+1):
    if(a%i==0):
        k=k+1
if(k<=0):
    print("Number is prime")
else:
    print("Number isn't prime")
Smoggy Skipper

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 premier dans Python”

Questions similaires à “Numéro premier dans Python”

Plus de réponses similaires à “Numéro premier dans Python” dans Python

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code