The Python range()
and xrange()
functions, like the Python slice notation, do not include the end value; xrange(2, 10)
generates 8 numbers from 2
to 9
, not 10. n + 1
makes sure n
is part of the generated range.
Use eratosthenes(7)
or eratosthenes(11)
to see the difference; 10 is not a prime number and is being filtered out.