def findMinAndMax(L): if len(L) == 0: return (None,None) else: mi = L[0] ma = L[0] for l in L: if l < mi: mi = l elif l > ma: ma = l return (mi,ma) # 测试 if findMinAndMax([]) != (None, None): print('测试失败!') elif findMinAndMax([7]) != (7, 7): print('测试失败!') elif findMinAndMax([7, 1]) != (1, 7): print('测试失败!') elif findMinAndMax([7, 1, 3, 9, 5]) != (1, 9): print('测试失败!') else: print('测试成功!')
标签:elif,ma,tuple,Python,mi,list,None,print,findMinAndMax From: https://www.cnblogs.com/zhng365/p/17394597.html