我在这里缺少技术词,但这里的问题是将 int 更改为 float 或 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