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=", ")