Discuss / Python / 指出老师的一处有问题的地方,请老师看看

指出老师的一处有问题的地方,请老师看看

Topic source

虚幽魂

#1 Created at ... [Delete] [Delete and Lock User]

def primes(): yield 2 it = _odd_iter() # 初始序列 while True: n = next(it) # 返回序列的第一个数 yield n it = filter(_not_divisible(n), it) # 构造新序列 **这个函数_not_divisible()里面不应该有n,会报错的……

虚幽魂

#2 Created at ... [Delete] [Delete and Lock User]

但是_not_divisible(n)中没有n参数,出现结果不是素数,何解?

虚幽魂

#3 Created at ... [Delete] [Delete and Lock User]

按照老师文中敲,报这个错 [root@localhost ~]# python sushu.py 2 3 Traceback (most recent call last): File "sushu.py", line 17, in <module> for n in primes(): File "sushu.py", line 16, in primes it = filter(not_divisible(n),it) TypeError: not_divisible() takes 0 positional arguments but 1 was given

虚幽魂

#4 Created at ... [Delete] [Delete and Lock User]

好吧,我已经找到了错误地方,是我自己的原因,少敲了一个字符…………


  • 1

Reply