Discuss / Python / 迭代作业

迭代作业

Topic source

烈可烈

#1 Created at ... [Delete] [Delete and Lock User]
def findMinAndMax(L):
    if not L:
        return None, None
    max_temp = L[0]
    min_temp = L[0]
    for va in L:
        if va > max_temp:
            max_temp = va
        if va < min_temp:
            min_temp = va

    return min_temp, max_temp

# 测试
print(findMinAndMax([-1, 2, 3, 4, 5, 6, 7, 10, 0]))
print(findMinAndMax([]))

`


  • 1

Reply