Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem Complete the function recursiveCount() to take in an array and a target

ID: 3719959 • Letter: P

Question

Problem

Complete the function recursiveCount() to take in an array and a target element and return the number of times this element appears in the array.

You must implement this using recursion :) You may also not slice the array (i.e. must use a helper).

Example

recursiveCount([1, 3, 4, 3, 2], 3) # 2

1- def recursiveCount(array, target): Problem Complete the function recursiveCount () to take in an array and a target element and return the number of times this element appears in the array You must implement this using recursion :) You may also not slice the array (i.e. must use a helper) Example recursiveCount ([1, 3, 4, 3, 2), 3) # 2

Explanation / Answer

Solution:

code:

def recusiveCount(array, target):

count= 0

     if len(array)== 1:

if array[0] == target:

        return 1

else:  

return 0

     else:

        return count+recursiveCount(array[1:], target)

I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote