In your loop you are reassigning the list
f to be an int
by doing
f=rem*1
which is the cause of your error. Assuming your list f is f = [1,2,3]
and rem
is say, 3. This is what is happening
In [149]: f = [1,2,3]
In [150]: rem = 3
In [151]: f = rem * 1
In [152]: f
Out[152]: 3
So on the next iteration f[0] makes no sense, since f is no longer a list. Change
f = rem * 1
to
f[i] = rem * 1
Also, the last line in your code will throw an error, since you are trying to find length of an integer. rem
in your code is not a list, but an integer, so it you can not do indexing on it.