ここで技術用語が欠落していますが、ここでの問題は、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()エラー -- andなどの関数で修正しようとしましfloat()たが、それでも持続します:
TypeError: 'float' object cannot be interpreted as an integer