MAX = 10000
def get_dicimal(target_number) :
i = 1
while i <= target_number :
if target_number % i == 0 :
if i == 1 :
i = i + 1
elif i == target_number :
return True
else :
return False
else :
i = i + 1
dicimal_list = []
target_list = list(range(2, MAX))
print(target_list)
for i in target_list :
a = get_dicimal(i)
print(i, a)
if a == True :
dicimal_list.append(i)
for k in range(1, int(MAX / i)) :
try :
target_list.remove(i * k)
except :
pass
else :
pass
print(target_list)
print(dicimal_list)
result get_dicimal(3) is True but in for loop in line 23, it ignores number 3
so target_list result like this [3, 7, 9, 13, 19, 21, 27, 31, 39, 43, 49, 57, 61, 63, 71...
and dicimal_list = [2, 5, 11, 17, 23, 29, 37, 41, 47, 53, 59, 67, 73, 83, 97, 103, 109...
I guess it was caused by index problem but I don't know why.
It can't be expressed in for loop like i did?
I'm newbie so please teach me.