Please help with indent i think my indent is wrong but i am not sure Implement a
ID: 3865467 • Letter: P
Question
Please help with indent i think my indent is wrong but i am not sure
Implement a function that meets the specifications below. def max_val(t): """ t, tuple or list Each element of t is either an int, a tuple, or a list No tuple or list is empty Returns the maximum int in t or (recursively) in an element of t """ # Your code here For example, max_val((5, (1, 2), [[1], [2]])) returns 5. max_val((5, (1, 2), [[l], [9]])) returns 9. Paste your entire function, including the definition, in the box below. Do not leave any debugging print statements. def max_val(t): global max if isinstance(t, int): if t > max: max = t else: for item in t: max_val(item) max = theta t = [1, [2, 3], (4, 7)] max_val(t) print(max)Explanation / Answer
It is working as expected. There is no indent error. I have compiled and run the program successfully. It even gave me 7 as output which is the required output.
My program same as your program
def max_val(t):
global max
if isinstance(t,int):
if t>max:
max=t
else:
for item in t:
max_val(item)
max=0
t=[1,[2,3],(4,7)]
max_val(t)
print (max)