Исправление задачи (генератор простых чисел) с дня пересдачи (10.01.2023)
supermaster-dev
MexTest 2 years ago
parent feb92564b2
commit 2c865b78b1
  1. 27
      prime_gen004(change).py

@ -0,0 +1,27 @@
def prime_generator(top = 0):
primes: list = []
number = 1
while number < top:
number += 1
if len(primes) == 0 and number == 2:
primes.append(number)
yield number
j = len(primes) - 1
while j >= 0:
if number % primes[j] == 0:
break
j -= 1
if j == -1:
primes.append(number)
yield number
'''Проверка выражений'''
prime_list = [n for n in prime_generator(258)]
prime_gen_object = (n for n in prime_generator(123))
print(prime_list)
print(prime_gen_object)
for i in prime_gen_object:
print(i, end=", ")
Loading…
Cancel
Save