Discuss / Python / 作业

作业

Topic source

南墙小生

#1 Created at ... [Delete] [Delete and Lock User]
def find_min_max(L):
    if not isinstance(L, (list, tuple)):
        raise TypeError('L is not list or tuple')
    if len(L) == 0:
        return (None, None)
    min_num = L[0]
    max_num = L[0]
    for x in L:
        if x > max_num:
            max_num = x
        elif x < min_num:
            min_num = x
    return (min_num, max_num)

  • 1

Reply