15,125,299 members
See more:
`Create a program that asks the user for an integer greater than or equal to 100. Generate a list of primes up to and including this number. Print the list to the screen on a single line. You may assume that the user will enter valid numeric input in the correct range.​ how to do in python`

What I have tried:

```def makeprimes( upper ):
count = 2
primes = [1]

while count <= upper:
prime = True
for i in range(2, count):
if count % i == 0:
prime = False
break
if prime:
primes.append(count)

count = count + 1

return primes```
Posted
Updated 30-Nov-20 10:04am

## Solution 1

Quote:
Create a program which displays primes numbers in sieve of eratosthenes

The problem with your code is that it build a list of primes by using trial division algorithm. And you use the brute force variant.
You need to study the Eratosthenes sieve: Sieve of Eratosthenes - Wikipedia[^]
Sieve of Eratosthenes get the result without resorting to divisions.
CPallini 1-Dec-20 2:10am

5.
Patrice T 1-Dec-20 2:33am

Thank you

## Solution 2

Construct an array of all possible numbers in a the range.
Loop through all numbers in the range, eliminating all multiples of that from the array.
What remains are the prime numbers.

Obviously there are quite a few tricks you can do to improve performance here!

But this is your homework, so I'll let you work them out for yourself.
CPallini 1-Dec-20 2:10am

5.