我按照老师的代码敲得那个素数的小练
Topic source我运行了一下 发现没有99这个数 你再试下
def _odd_iter():
n = 1
while True:
n = n + 2
yield n
def _not_divisible(n):
return lambda x: x % n > 0
def primes():
yield 2
it = _odd_iter() # 初始序列
while True:
n = next(it) # 返回序列的第一个数
yield n
it = filter(_not_divisible(n), it) # 构造新序列
for n in primes():
if n < 100:
print(n)
else:
break
- 1
麻豆豆--
我是按照老师写的那个素数的代码敲得,可是结果貌似不太对吧。 运行小于100的结果里有99,99能被3除开吧?