I wrote a prime number generator:
def primes(): prime = True i = 1 while True: i += 1 for j in range(2, i): if i % j == 0: prime = False if prime: yield i else: prime = True But something I do not understand how to use it. I do as a challenge:
x = primes() print(x) Displays an object, not a number.
In the case of such a call print(next(primes())) all the time I get 2 on the output.
How to use generators?