How to solve the problem by FOLLOWING this python code format? def createList(n):     #Base Case/s     #TODO: Add conditions here for your base case/s     #if :         #return        #Recursive Case/s     #TODO: Add conditions here for your recursive case/s     #else:         #return     #remove the line after this once you've completed all the TODO for this function     return [] def removeMultiples(x, arr):       #Base Case/s     #TODO: Add conditions here for your base case/s     #if :         #return        #Recursive Case/s     #TODO: Add conditions here for your recursive case/s     #else:         #return     #remove the line after this once you've completed all the TODO for this function     return []     def Sieve_of_Eratosthenes(list):   #Base Case/s   if len(list) < 1 :     return list   #Recursive Case/s   else:     return  [list[0]] + Sieve_of_Eratosthenes(removeMultiples(list[0], list[1:])) if __name__ == "__main__":   n = int(input("Enter n: "))   print(n)   list = createList(n)   #Solution 1   primes = Sieve_of_Eratosthenes(list)   print(primes)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

How to solve the problem by FOLLOWING this python code format?

def createList(n):
    #Base Case/s
    #TODO: Add conditions here for your base case/s
    #if <condition> :
        #return <value>
  
    #Recursive Case/s
    #TODO: Add conditions here for your recursive case/s
    #else:
        #return <operation and recursive call>

    #remove the line after this once you've completed all the TODO for this function
    return []

def removeMultiples(x, arr):
      #Base Case/s
    #TODO: Add conditions here for your base case/s
    #if <condition> :
        #return <value>
  
    #Recursive Case/s
    #TODO: Add conditions here for your recursive case/s
    #else:
        #return <operation and recursive call>

    #remove the line after this once you've completed all the TODO for this function
    return []
   
def Sieve_of_Eratosthenes(list):
  #Base Case/s
  if len(list) < 1 :
    return list
  #Recursive Case/s
  else:
    return  [list[0]] + Sieve_of_Eratosthenes(removeMultiples(list[0], list[1:]))

if __name__ == "__main__":
  n = int(input("Enter n: "))
  print(n)
  list = createList(n)
  #Solution 1
  primes = Sieve_of_Eratosthenes(list)
  print(primes)

You are to do a recursive implementation of the Sieve of Eratosthenes, an ancient algorithm
for finding all prime numbers up to a given limit, n, which we will let the user input.
We will be modifying this algorithm a bit. Instead of just marking the multiples of prime
numbers, we will directly remove them by creating our own helper
function, removeMultiples). This recursive function takes in a number, n, and a list and
returns a list that doesn't contain the multiples of n.
We will also create a recursive function, greateList), that takes in the user input n and returns an
array of integers from 2 through n (i.e. [2, 3, 4, ..., n]). You can use this list when testing
the removeMultiples() helper function above.
Our last recursive function is the SieveOfEratosthenes). This takes in a list and returns a list of
prime numbers from the input list. This function is already fully working in the given template to
make you focus more on implementing the first two. This is intended to serve as a guide on how to
create or manipulate arrays in a recursive manner.
Transcribed Image Text:You are to do a recursive implementation of the Sieve of Eratosthenes, an ancient algorithm for finding all prime numbers up to a given limit, n, which we will let the user input. We will be modifying this algorithm a bit. Instead of just marking the multiples of prime numbers, we will directly remove them by creating our own helper function, removeMultiples). This recursive function takes in a number, n, and a list and returns a list that doesn't contain the multiples of n. We will also create a recursive function, greateList), that takes in the user input n and returns an array of integers from 2 through n (i.e. [2, 3, 4, ..., n]). You can use this list when testing the removeMultiples() helper function above. Our last recursive function is the SieveOfEratosthenes). This takes in a list and returns a list of prime numbers from the input list. This function is already fully working in the given template to make you focus more on implementing the first two. This is intended to serve as a guide on how to create or manipulate arrays in a recursive manner.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Computational Systems
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education