Question: Write a new Python program that uses the Sieve of Eratosthenes to find prime numbers. A number is said to a prime number if it

 Write a new Python program that uses the "Sieve of Eratosthenes"

Write a new Python program that uses the "Sieve of Eratosthenes" to find prime numbers. A number is said to a prime number if it cannot be divided evenly by any other number (except 1). For example, 2, 3, 5, 7 and 11 are prime. 4 is not prime because it can be divided by 2, and so on. The "Sieve of Eratosthenes" is a pretty simple idea: you list out all of the numbers you're interested in, and then starting at 2, you cross out all of the multiples of 2. After that, you cross out all the multiples of 3. Then you skip 4 (since it's already crossed out), and you cross out all the multiples of 5, and so on. You can read more about it, as well as see an animation, in Wikipedia as well as many other web pages online. Your Python program should include a function that takes an argument and finds all of the prime numbers up to and including that number. It does this by creating two Python lists, one of all of the non-prime numbers and another of all the primes. A counting loop moving from 2 to the desired end point simply checks to see if a number is already in the "non- primes" list and if it is, skips it. But if not, that number is added to the "primes" list and all of its multiples are added to the "non-primes" list. Your program should ask the user to enter a number, then it should report whether that number is prime, or not; it should then list all of the prime numbers up to the user's entered value and state how many prime numbers there are

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!