You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
702 B
28 lines
702 B
2 years ago
|
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=", ")
|