Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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" 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started