I'm not seeing how can I get rid of the error. Is this happening because of the use of while
? I want to print the first 12 non-prime numbers.
from math import sqrt
from itertools import count, islice
def is_prime(n):
if n < 2:
return False
for number in islice(count(2), int(sqrt(n) - 1)):
if n % number == 0:
return False
return True
def positive_integers_generator():
n = 1
while True:
x = yield n
if x is not None:
n = x
else:
n += 1
k = 12
g = positive_integers_generator()
count = 0
while count < k:
value = next(g)
if not is_prime(value):
count += 1
print(value)
You have replaced the count
function you imported with an integer, sicne you are starting your main with count = 0
. Next time you try to call it as a function, you get this error.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.