我在一臺安裝了Python 2.6的Windows XP PC上工作,我試圖解決項目歐拉問題,但是每當我執行代碼解釋器掛起。我已經通過PyScripter,IDLE和MonkeyStudio進行了調試,但它仍然無法工作,即使像15這樣的小數值。運行時崩潰的一個非常基本的Python程序
我簡直不明白爲什麼。你能幫我解決嗎?
下面的代碼:
"""Project Euler Problem 3
Author: A"""
num = 15
prime = [1]
x = long (round(num/2))
def ifprime (x):
""" Defining the function that checks if the number is prime or not"""
""" Checking if the passed number is prime or not"""
y = long(round(x/2))
while y > 0:
if x%y == 0:
return False
y -= 1
return True
while x > 0:
if num%x == 0:
if ifprime(x):
print "I've found a prime! "
print x
prime[len(prime):] = [x]
x -= 1
這不是一個無限循環? – quantumSoup 2010-09-02 17:13:37
你說你試過調試過它......你找不到自己的錯在哪裏嗎? (我做了,這很明顯是怎麼回事) – Kena 2010-09-02 17:16:07
我不知道爲什麼我沒有看到它。我剛剛在幾天前開始編碼。所以,這可能與它有關。 – 2010-09-02 17:22:27