From 2c865b78b11817e70207d9aa85bb929c7b7e8170 Mon Sep 17 00:00:00 2001 From: MexTest Date: Fri, 13 Jan 2023 07:54:19 +0000 Subject: [PATCH] - MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Исправление задачи (генератор простых чисел) с дня пересдачи (10.01.2023) --- prime_gen004(change).py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 prime_gen004(change).py diff --git a/prime_gen004(change).py b/prime_gen004(change).py new file mode 100644 index 0000000..36fa2fc --- /dev/null +++ b/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=", ")