Question: Now, here is a correct implementation of the recursive case of num_integers def num_integers(obj: Union [int, List]) -int: if isinstance(obj, int): else: # Recursive part
Now, here is a correct implementation of the recursive case of num_integers def num_integers(obj: Union [int, List]) -int: if isinstance(obj, int): else: # Recursive part for sublist in obj: s num-integers (sublist) +# return s This implementation uses the basic "loop through each sub-nested-list" pattern you read about in the notes, together with an accumulator variable s that's eventually returned. Practice tracing through the call num_elements(15, [105, 131, te, 1, 2, 3, 4, ) by completing the following table, which shows how s changes after each loop iteration, assuming each recursive call is correct. Value of s after processing sublist 0 (initial value) sublist num_integers(sublist) (15, (105, 13]] 4 You should find that the final value of s (in the bottom-right cell of the table) matches the correct output of num_elements([115, [105, 13], [e, 1, 2, 31, 4, 1) This verifies that the recursive step is correct, assuming each recursive call is correct
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
