Question: Using Python 3+ Write a recursive function maximum that takes an arbitrarily nested list containing numbers and returns the maximum item in that list. If

Using Python 3+

Write a recursive function maximum that takes an arbitrarily nested list containing numbers and returns the maximum item in that list. If given a number (not a list), then the maximum is obviously that number. If given a (nested) list, then you should accumulate a list consisting of the maximum of each branch, and return the max of the newly accumulated list. Write the base case first, then get it to work for a non-nested list, then finally for a nested list.

The following output must be met:

>>> maximum( 7 ) 7 >>> maximum( [7,8] ) 8 >>> maximum( [7,8,[9,10],[[11,[12]],13]] ) 13 >>> >>> exec(' import random random.seed(0) def t(n): if n==0: return random.randrange(10) elif random.randrange(2): return [ random.randrange(10), t(n-1)] else: return [t(n-1),random.randrange(10),t(n-1)] ') >>> [ maximum(t(i)) for i in range(4)] [6, 4, 7, 9] >>>

Write a recursive function printstack that prints a stack of cups with a given number of rows. The function MUST be recursive and is not allowed to use a loop (but can use multiplication with strings). Hint: have the function allow an additional parameter, and indentation value, see the last test run. Sample output:

The following output must be met:

>>> printstack(1) U >>> printstack(2) U U U >>> printstack(3) U U U U U U >>> printstack(4) U U U U U U U U U U >>> printstack(4,3) U U U U U U U U U U

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!