def main(): for n in primes(): if n < 1000: print(n) else: breakdef _odd_filer(): n = 1 while True: n = n + 2 yield ndef _not_divisible(n): return lambda x:x % n>0def primes(): yield 2 it = _odd_filer() while True: n = next(it) yield n it = filter(_not_divisible(n),it)if __name__ == '_main_': main()输出只显示这一句:>> runfile('D:/python/butaidong.py', wdir='D:/python')>>> runfile('D:/python/butaidong.py', wdir='D:/python')没有结果
1 回答
已采纳
Nelson_Zhao
TA贡献21条经验 获得超4个赞
倒数第二句错误。
if __name__ == "_main_"
main的前后都是双下划线,题主写的单下划线。改为:
if __name__ == "__main__"
添加回答
举报
0/150
提交
取消