Question
4. Write a recursive function recStrMerge () that takes two strings s1 and s2 as parameters and returns a string that consists of the two
4. Write a recursive function recStrMerge() that takes two strings s1 and s2 as parameters and returns a string that consists of the two strings merged together. The string returned by the function should the first character of s1 followed by the first character of s2 followed by the second character of s1 followed by the second character of s2, etc. If one string runs out of characters before the other, then the remaining string should appear at the end of the merged string. The only string functions you are allowed to use are len(), concatention, indexing (s[i] for an integer i), or slicing (s[i:j] for integers i and j). The following shows several sample runs of the function:
5. 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 (lst[i] for some integer i), slicing (lst[i:j] for some integers i and j), or len(). 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 following shows the behavior of the function on some sample parameters.
Please remember that the 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:
Python 3.41 Shell File Edit the Debug Options Windows Help recStr (1 abc xyz') Merge axbycz s recStr Merge (1 abcd 1234561) S alb2c3d 456 recStr Merge abcdefghi', t() recStr Merge abc abc recStr Merge (11, 1231) 123 recStr Merge (11, Ln: 59 col 4Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started