用filter求素数
请教大家!def _odd_iter():
n=1
while True:
n=n+2
yield n
def _not_divisible(n):
return lambda x: x % n > 0
def primes():
yiled 2#为什么我的这行报错了呢?
it = _odd_iter()
while True:
n=next(it)
yiled n
it=filter(_not_divisible(n),it)
for n in primes():
if n < 1000:
print(n)
else:
break
yiled 2 #这行命令我在VSCode里面运行时报错,请问大家为什么呢?
命令来源:廖雪峰的官方网站https://www.liaoxuefeng.com/wiki/1016959663602400/1017404530360000
啊对不起,我瞎了!我将field写成了filed...原谅我{:10_266:}
页:
[1]