【发布时间】:2014-05-02 07:32:13
【问题描述】:
我正在使用下面的代码寻找 2500 的质因数,但我的代码目前只打印 2,我不确定为什么会这样。
no = 2500
count = 0
# Finding factors of 2500
for i in range(1,no):
if no%i == 0:
# Now that the factors have been found, the prime factors will be determined
for x in range(1,no):
if i%x==0:
count = count + 1
"""Checking to see if the factor of 2500, itself only has two factor implying it is prime"""
if count == 2:
print i
谢谢
【问题讨论】:
-
算法对我来说意义不大,需要解释一下吗?
-
缩进错误,只有在 count==2 时才会打印...
-
第二个
for循环不应该进一步缩进吗? -
@filmor 我希望它更清楚