我重新设计了程序以获得大素数。现在它工作正常,除了在打印所有输出之后我最后得到大量红色短语。有人可以告诉我为什么吗?
输出的结尾是:
(100000939.0, 'is prime')
(100000963.0, 'is prime')
(100000969.0, 'is prime')
错误是
Traceback (most recent call last):
File "C:/Users/Marcela/Documents/Prime numbers to 100", line 48, in <module>
loopfunction()
File "C:/Users/Marcela/Documents/Prime numbers to 100", line 35, in loopfunction
loopfunction()
File "C:/Users/Marcela/Documents/Prime numbers to 100", line 35, in loopfunction
loopfunction()
File "C:/Users/Marcela/Documents/Prime numbers to 100", line 35, in loopfunction
loopfunction()
...(many lines of it, the int ends with:)
File "C:/Users/Marcela/Documents/Prime numbers to 100", line 13, in loopfunction
while index <= 200000000.0:
RuntimeError: maximum recursion depth exceeded in cmp
这是脚本:
from __future__ import division
import sys
index=100000000.0
checker=2.0
def loopfunction():
global index
global checker
checker=2
while index <= 200000000.0:
if index>=200000001:
sys.exit(1)
while checker<=14473.0:
div = index/checker
roundiv=round(index/checker, 0)
if index == 1:
print (index, "is prime")
checker=2
index=index+1
loopfunction()
if checker == index:
print (index, "is prime")
checker=2
index=index+1
loopfunction()
if roundiv==div:
checker=2
index=index+1
loopfunction()
if checker==14473.0:
print (index, "is prime")
checker=2
index=index+1
loopfunction()
checker = checker +1
loopfunction()