Remove multiples of numbers out of a list – Python

There is much simpler ways to get the same result(prime numbers < 10000)
but if you insist to use that code you can add a simple loop

def main():
    _list_ = []
    for i in range(2, 10001):
        _list_.append(i)

    k=0
    while k<10000-2:# n starts from 2
        n = _list_[k]
        multiple = 2*n
        while multiple <= 10000:
            multiple += n
            _list_.remove(multiple)
        k = k + 1
main()

Leave a Comment