“Python -Code zum Drucken von Primzahlen” Code-Antworten

Python -Programm, um N -Primzahlen zu finden

num = 10
for i in range(2,num+1):
    for j in range(2,i):
        if(i%j == 0):
            break
    else:
        print(i)
GrepDAD

Python -Programm zum Drucken von Primzahlen in einem Intervall

lower = 800
upper = 900
print("Print the number's from ",lower," and ",upper,".")
for num in range(lower,upper + 1):
  if num > 1:
    for i in range(2, num):
      if (num % i) == 0:
        break
    else:
      print(num)    
Exuberant Elk

Python -Code zum Drucken von Primzahlen

# 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

Primzahlen Python

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

Primzahl in 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

Python -Programm Prime -Nummer

#prime number or composit number
number=int(input('print number:'))
a=1
while number>a:
    if number%a ==0:
        a+=1
        print("Its composit 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##

Ähnliche Antworten wie “Python -Code zum Drucken von Primzahlen”

Fragen ähnlich wie “Python -Code zum Drucken von Primzahlen”

Weitere verwandte Antworten zu “Python -Code zum Drucken von Primzahlen” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen