Python Programming: An Introduction to Computer Science, 3rd Ed.
Python Programming: An Introduction to Computer Science, 3rd Ed.
3rd Edition
ISBN: 9781590282755
Author: John Zelle
Publisher: Franklin, Beedle & Associates
bartleby

Videos

Question
Book Icon
Chapter 11, Problem 10PE
Program Plan Intro

Implementation of sieve algorithm

Program plan:

  • Define the “sieve_era()” function,
    • Create empty list.
    • Create “while” loop,
      • Append the first element to the new list using “append()” method.
      • Make a “try” statement for exception.
        • Create “for” loop,
          • Check whether the list element is divided by the first element.
          • If it is “True” remove the element.
      • If any exception occurs, handle the exception,
        • Keep the new list.
    • Return new list.
  • Define the “main()” function,
    • Get the input from the user.
    • Create empty list.
    • Create “for” loop,
      • Fill the new list using “append()” method.
    • Assign the list return from “sieve_era()” function.
    • Remove the element “4” from the list.
    • Print the list.
  • Call the “main()” function.

Blurred answer
Students have asked these similar questions
Given a list of integers, you want to know whether it is possible to divide the integers into two sets, so that the sum of one set is odd, and the sum of the other set is a multiple of 10. Every integer must be in one set or the other. You can write a recursive helper method that takes any number of arguments and then call it inside the method, but you cannot use any loops. Test cases: oddAndTen([5, 5, 3]) true oddAndTen ([5, 5, 4]) oddAndTen ([5, 5, 4, 1]) false true
A prime number is an integer greater than 1 whose only positive divisors are 1 and the integer itself. The Greek mathematician Eratosthenes developed an algorithm, known as the Sieve of Eratosthenes, for finding all prime numbers less than or equal to a given number n—that is, all primes in the range 2 through n. Consider the list of numbers from 2 through n. Two is the first prime number, but the multiples of 2 (4, 6, 8,...) are not, and so they are crossed out in the list. Hie first number after 2 that was not crossed out is 3, the next prime. We then cross out from the list all higher multiples of 3 (6, 9, 12,…). The next number not crossed out is 5, the next prime, and so we cross out all higher multiples of 5 (10, 15, 20,…). We repeat this procedure until we reach the first number in the list that has not been crossed out and whose square is greater than n. All the numbers that remain in the list are the primes from 2 through n. Write a program that uses this sieve method and an…
Given a list of integers, we want to know whether it is possible to choose a subset of some of the integers, such that the integers in the subset adds up to the given sum recursively. We also want that if an integer is chosen to be in the sum, the integer next to it in the list must be skipped and not chosen to be in the sum. Do not use any loops or regular expressions. Test cases: skipSum([2, 5, 10, 6], 12) true skipSum([2, 5, 10, 6], 7) false skipSum([2, 5, 10, 6], 16) false Given code: public static boolean skipSum (List list, int sum) { // call your recursive helper method return skipSumHelper (list, e, sum); 1. 2. 3. 4.
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Introduction to Big O Notation and Time Complexity (Data Structures & Algorithms #7); Author: CS Dojo;https://www.youtube.com/watch?v=D6xkbGLQesk;License: Standard YouTube License, CC-BY