0

The code below returns a list of lists of reminders. for some reason sometimes it returns all integers, while in other cases it return a mix of integers with doubles:

import itertools

def get_factors_list(n):
    list=[]
    curr_n = n
    sqrt = int(n**0.5)+1
    for i in range(2,sqrt):
        if(curr_n%i==0):

            l=[1]
            count=0
            while(curr_n%i==0):
                count+=1
                curr_n=curr_n/i
                l.append(int(i**count))

            list.append(l)


            sqrt = int(curr_n**0.5)+1
            if(curr_n==1):
                return list

    list.append([1,curr_n])
    return list

num1=28
num2=140
l1=get_factors_list(num1)
l2=get_factors_list(num2)
print(l1) #[[1, 2, 4], [1, 7.0]] # note `7.0`
print(l2) #[[1, 2, 4], [1, 5], [1, 7]] # note `7`

What causes this discrepancy?

P.S. I know a fast and dirty fix (int(al[i][j]), but I am asking about the causes.

Stepan
  • 1,514
  • 17
  • 35

0 Answers0