Discuss / Python / 求素数的方法实际可运行么?

求素数的方法实际可运行么?

Topic source

贝司特曼

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

我完全复制文中的代码,但是电脑一运行就卡死。

ABELWONG20

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

我只能输出2和3,然后就不行了。有人知道为什么吗

贝司特曼

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

我也是输出2和3,然后就卡死了, 运行前打开了任务管理器,可以看到python占用内存飙升到2G

一刻道生

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

def p(): def z(): n=1 while True: n += 2 yield n def sx(n): return lambda x: x % n > 0 yield 2 i=z() while True: n = next(i) yield n i = filter(sx(n),i)

for a in p(): if a>100: break print(a)

能用啊

贝司特曼

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

拿到另外一台电脑上可以运行,但自己电脑就会卡死。难道是配置环境有问题?

廖雪峰

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

只能在python 3运行

贝司特曼

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

问题搞清楚了,电脑里装了2和3两个版本,但是sublime txt的按键绑定的是Python 2。谢谢!


  • 1

Reply