Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function called recursiveFind that takes a list of integers as input and walks down the list recursively, from the first element of the

Write a function called recursiveFind that takes a list of integers as input and "walks down the list" recursively, from the first element of the list to the last element of the list, searching for the integer value assigned to a variable called find_target (find_target is a global variable that is assigned a value outside recursiveFind, but that is also used inside recursiveFind for comparison tests; see below HINTS). Your program must print out to the command console the number of times that find_target is discovered in the list, like this:

 Total occurrences of find_target in list: 2. 

Furthermore, your program MUST NOT ALTER the original input list! Remember: Lists are MUTABLE! Thus, altering the original input list inside recursiveFind (for example, by "popping" it; see below HINTS) may get you into trouble becauses the altered list will then be passed into each subsequent, recursive call to the function recursiveFind.

Your program must be able to handle input lists of arbitrary length, including the empty list. Upon entry into recursiveFind function, the function must first check to see if the incoming list is empty. To do that, and assuming that the incoming list is assigned to a variable called lst, use the following IF statement test:

 if not lst: 

That test will return True when lst is equal to the empty list (i.e., when it equals [ ] ). If an empty list was input to recursiveFind, then your function recursiveFind should return the value 0 immediately.

Next, and assuming that the input list is not empty, you should POP THE FIRST ELEMENT OF THE LIST (assuming that your list is assigned a variable called lst; we pop the first element of lst by issuing the following command: lst.pop(0) ).

Popping the first element a list does two things: (1) It produces a value that you can compare immediately using an IF statement; and (2) The list is reduced in size by one element. If by popping the list you detect that the value popped is NOT EQUAL TO find_target, then recursiveFind should return the value 0 + the value returned by another call to recursiveFind. Otherwise, if you detect that the value popped is, in fact, EQUAL TO find_target, then recursiveFind should return the value of 1 + the value returned by another call to recursiveFind.

MUST BE SOLVED RECURSIVELY please elaborate the process too!

PYTHON ONLY

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

Advanced MySQL 8 Discover The Full Potential Of MySQL And Ensure High Performance Of Your Database

Authors: Eric Vanier ,Birju Shah ,Tejaswi Malepati

1st Edition

1788834445, 978-1788834445

More Books

Students also viewed these Databases questions

Question

c. What were you expected to do when you grew up?

Answered: 1 week ago