我在這裏丟失了技術詞,但這裏的問題是要麼將int更改爲float,要麼將其更改爲int。解釋因子分析中的float-int問題
def factorize(n):
def isPrime(n):
return not [x for x in range(2,int(math.sqrt(n)))
if n%x == 0]
primes = []
candidates = range(2,n+1)
candidate = 2
while not primes and candidate in candidates:
if n%candidate == 0 and isPrime(candidate):
# WHY ERROR?
#I have tried here to add float(), int() but cannot understand why it returns err
primes = primes + [float(candidate)] + float(factorize(n/candidate))
candidate += 1
return primes
的錯誤 - 試圖與功能,如int()
和float()
但仍固定它堅持:
TypeError: 'float' object cannot be interpreted as an integer
爲什麼浮動參與`factorize`函數呢? – dan04 2011-01-19 16:53:37
dan04:過度使用,殺死它。現在它可以工作,但仍然對其他問題感到疑惑,更有效? – hhh 2011-01-19 17:30:52