Here is what I have. The function works perfectly fine at filtering out composite numbers, but I can not figure out why it is printing duplicates of certain numbers:
def prime_filter(list):
prime_list = []
for i in list:
if i == 2:
prime_list.append(i)
if i > 1:
for n in range(2, i):
if(i % n == 0):
break
else:
prime_list.append(i)
print("The total number of prime numbers is: ", len(prime_list))
print(prime_list)
Here is my test of the function and the output it returns:
# test
test_list = [2, 3, 6, 8, 11]
prime_filter(test_list)
The total number of prime numbers is: 11
[2, 3, 11, 11, 11, 11, 11, 11, 11, 11, 11]
Anyone know how I can fix this? Any help is greatly appreciated.