我編寫了應該打印出100到200之間的素數的程序(我在程序中添加了一些額外的打印命令,以便我可以看到它的位置)任何人都可以給我一個暗示爲什麼它停在137,而腳本正在檢查這個數字?程序意外停止
謝謝!
下面是腳本:
import math
import sys
index=100.0
checker=2.0
def start():
print("A")
global index
while index<=200.0:
fu1()
if index>200.0:
end()
def fu1():
print ("B")
print ("checker", checker)
print ("index", index)
global index
global checker
varb=index/checker
varb2=round(index/checker, 0)
if checker>=index:
print ("C")
print(index)
index=index+1.0
checker=2.0
start()
if varb2==varb:
print("D")
checker=2.0
index=index+1.0
start()
checker=checker+1.0
fu1()
def end():
print("E")
print("ENDED")
sys.exit()
start()
也許這一個:http://stackoverflow.com/questions/3289430/python-recursion – PeterMmm
爲什麼'fu1'自稱? –
@DavidSchwartz - 遞歸? ;)雖然有點奇怪的遞歸,但我承認。 – weronika