0
我试图运行此代码时,我的电脑基本崩溃。Eratosthenes筛不工作
有人请指出为什么?
我意识到调整列表并不是最有效的方式,但即使在下输入任何数字也不会产生任何结果,并会使得我的电脑崩溃。
我的目标是建立一个类,我可以存储某人的号码的实例,这样我就不必再次运行该功能,如果有人想拨打相同的号码。
class eratosthenes(object):
def __init__(self, b):
self.b = b
count1 = 2
self.lst = []
while count1 <= b:
self.lst.append(count1)
count1+=1
def sieve(self):
self.count2 = 2
while self.count2 < self.b/2.0:
for i in self.lst:
if i%self.count2==0:
self.lst.remove(i)
self.count2+=1
a=raw_input("How far are you willing to go in this search for what you seek, young traveler?: ")
q = eratosthenes(a)
print q.sieve()