Функция:
def get_prime_numbers(n): prime_numbers = [] for number in range(2, n+1): for prime in prime_numbers: if number % prime == 0: break else: prime_numbers.append(number) return prime_numbers
class PrimeNumbers: def __init__(self, n): self.n = n self.number = 0 self.prime = 2 def __iter__(self): self.number = 0 self.prime = 2 return self def __next__(self): self.number += 1 if self.number > self.n: raise StopIteration() for self.number in range(2, self.n+1): if self.number % self.prime != 0: self.prime = self.number return self.prime prime_number_iterator = PrimeNumbers(n=10000) for number in prime_number_iterator: print(number)