I am having an interesting problem with Python. My task is to calculate all prime factors of a given number. This is my code:
import math
def func(number):
while number % 2 == 0:
number = number / 2
print("2")
for i in range(3, math.ceil(math.sqrt(number)) + 1, 2):
while number % i == 0:
number = number / i
print(i)
if number > 2:
print(str(int(number)))
Normally this code works and there is no problem. However, say we pass 211,111,122,222,223,420 to func. It will print these factors: 2, 2, 2, 2, 2, 2, 19, 97, 178980536338. This obviously can't be true as the number whose factors we want to find ends with zero, which means that it must have at least one 5 among its factors. Right? In fact, if you multiple the printed factors, the result will be 211,111,122,222,223,424 (four units more than the passed number). What am I doing wrong?