
I'm trying to code a program that prints the factors of a number, just as shown in the attached image, but the outcome is totally not what I'm expecting. (I just want the code to return factors of the specified number.) What am I doing wrong and what is the correct way of doing it?
Code:
number=42
factor_list=[]
for num in range(1,number+1):
num=number/num
if (number%num)==0:
factor_list.append(num)
print(factor_list)
Output:
[42.0, 21.0, 14.0, 10.5, 7.0, 6.0, 5.25, 3.5, 3.0, 2.625, 2.0, 1.75, 1.5, 1.3125, 1.0]