九州体育网 - 十年信誉网站

关于作者

Discuss / Python / Max,Min必须先判断L存在后能力赋值

Max,Min必须先判断L存在后能力赋值

Topic source

def findMinAndMax(L): if not L: return None, None else: Max = L[0] Min = L[0] for x in L: if Max < x or Max == x: Max = x if Min > x or Min == x: Min = x return Min, Max

测试

if findMinAndMax([]) != (None, None): print('测试失败!1') elif findMinAndMax([7]) != (7, 7): print('测试失败!2') elif findMinAndMax([7, 1]) != (1, 7): print('测试失败!3') elif findMinAndMax([7, 1, 3, 9, 5]) != (1, 9): print('测试失败!4') else: print('测试胜利!')


  • 1

Reply

WARNING: You are using an old browser that does not support HTML5. Please choose a modern browser (Chrome / Microsoft Edge / Firefox / Sarafi) to get a good experience.