Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a recursive function recListSum () that takes an arbitrarily nested list as a parameter and returns the sum of the numbers in the list.

Write a recursive function recListSum() that takes an arbitrarily nested list as a parameter and returns the sum of the numbers in the list. You are not allowed to use any list methods in your function other than indexing (e.g. lst[i] for some integer i), slicing (e.g. lst[i:j] for some integers i and j), or len(). Solutions that use built-in functions rather than recursion to solve the problem will earn very little credit. You may assume that the initial value given to the function is a list, and your function does not have to behave in any reasonable way when given something other than a list as a parameter. The list may contain values of any type and you must only take the sum of the ones that are integers or floating point values. The type() function is helpful in determining what values can be found in the list. Numbers found within other collections (tuples, dictionaries, etc.) should not be included in the sum. The function should not alter the list in any way nor should it make a copy of the list and alter that. The following shows the behavior of the function on some sample parameters. Please remember that these examples are just that. Your function must work correctly on all valid parameters, and you may not make any assumptions about the number of nested sublists or the depth of the nesting in the list provided as a parameter to the function: NO LOOPS OF ANY SORT SINCE THIS IS A RECURSIVE FUNCTION

This is the output and in python please.

image text in transcribed

Python 3.6.4 Shell File Edit She Debug Options Window Help >>> val = recListSum ([]) >>val 0 >>val >>> val recListsum ( [ ' one. [ [ [ [ [ two' ] ] ] ] ] , three-4, 5.5, 'six' )) >>val 9.5 >>> val- recListSurm ( [1, [[[[['two'????], 'three', 4, 5.5, [['six']]]) >>val 10.5 >>> val - recListsum([1.5, CCCC'two']1]]], 'three, 4, 5.5, [['six']], 7]) >>val 18.0 >>val 0 Ln: 96 Col: 4

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_2

Step: 3

blur-text-image_3

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

Big Data, Mining, And Analytics Components Of Strategic Decision Making

Authors: Stephan Kudyba

1st Edition

1466568704, 9781466568709

More Books

Students also viewed these Databases questions

Question

What training do they require?

Answered: 1 week ago

Question

Why is the package an important venue for advertising messages?

Answered: 1 week ago

Question

What must happen for a message to be successfully processed?

Answered: 1 week ago

Question

How would you define direct marketing?

Answered: 1 week ago