Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function crossOffMultiples ( ) that takes a list of booleans and an integer from 2 to 1 0 0 as the starting value.

Write a function crossOffMultiples () that takes a list of booleans and an integer from 2 to 100 as the starting value. Your function will eliminate all the multiples by setting the value at the index of a multiple to false. Your list will start with all true values.
crossOffMutiples () will return the list.
Example: multiplesList of size 20.
\table[[,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],[multiplesList,true,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True]]
Result of function call: crossoffMultipes (multiplesList,2)
\table[[,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],[multiplesList,true,True,True,True,False,True,False,True,False,True,False,True,False,True,False,True,False,True,False,True,False]]
Create the multiplesList in the shell or in your py fileWrite a function sieve () that finds all the prime numbers from 2 to 100. You will use an ancient algorithm called the Sieve of Eratosthenes. Essentially the Sieve works by crossing off all the multiples of a number, starting with the integer 2. Once you cross off all the multiple values of 2, you then proceed to the next available integer, 3(not crossed off), and cross off its multiples. After sieve () has finished crossing off all possible multiples, your function will print the prime numbers. HINT: use your function crossOffMultiples () to reduce the complexity of your algorithm. Abstraction is your friend!ne numbers
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

AutoCAD Database Connectivity

Authors: Scott McFarlane

1st Edition

0766816400, 978-0766816404

More Books

Students also viewed these Databases questions