12347 - Python_mooc_3   

Description

Write a recursive function to find the largest integer in a tuple that can contain
integers, other tuples that contain integers (or other tuples alike). For example,
$ python3 -I maxInTuple.py

You may assume that tuples are non-empty, but it may contain minimally one
member (int or another tuple).

''' you should use the template of following.'''

import ast

def max_in_tuple(t):
    #Coding on here

    #Coding on here

    #Coding on here
if __name__ == '__main__':
    L = ast.literal_eval((input()))
    for testcase in L:
        print(f'max_in_tuple({testcase}) = {max_in_tuple(testcase)}')

 

Input

[(1, 5, (2, 7, (14, 6)), (9, 12)), (3, (7,), -5)]

Output

max_in_tuple((1, 5, (2, 7, (14, 6)), (9, 12))) = 14
max_in_tuple((3, (7,), -5)) = 7

Sample Input  Download

Sample Output  Download

Tags




Discuss