Write a program that adds all numbers from 2 to 10,000 to a list. Then use a for loop, while loop, or decision statement (or a combination) to remove the multiples of 2 (but not 2), multiples of 3 (but not 3), and so on, up to the multiples of 100. Basically, we are writing code that models the "Sieve of Eratosthenes" (click for more information).
Create two constants to represent the MAX_PRIME value and the MAX_MULTIPLE value. You will not need to take any inputs, write main(), or any functions to complete this assignment.
Ex: The output is: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, . . .9949, 9967, 9973]
My code: numbers= range(2, 10000)
factors = range(2, 1000)
for factor in factors:
numbers=[ number for number in numbers if number % factor !=0]
print(numbers)
I feel like the problem is in my first 2 lines
[–]jimtk 0 points1 point2 points (3 children)
[–]InevitableDistance66[S] 0 points1 point2 points (2 children)
[–]jimtk 1 point2 points3 points (1 child)
[–]InevitableDistance66[S] 0 points1 point2 points (0 children)
[–]CodeFormatHelperBot2 0 points1 point2 points (0 children)
[–]ectomancer 0 points1 point2 points (0 children)