【发布时间】:2010-09-02 17:09:05
【问题描述】:
我在装有 Python 2.6 的 Windows XP PC 上工作,我试图解决 Project Euler 问题,但每当我执行代码时,解释器就会挂起。我已经通过 PyScripter、IDLE 和 MonkeyStudio 对其进行了调试,但即使对于像 15 这样的微不足道的值,它仍然无法正常工作。
我只是不明白为什么。你能帮帮我吗?
代码如下:
"""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
【问题讨论】:
-
您说您尝试过调试它...您自己找不到问题所在吗? (我做到了,很明显发生了什么)
-
我不知道为什么我没有看到它。我几天前才开始编码。所以,这可能与它有关。