Discuss / Python / share my homework

share my homework

Topic source

郑男6

#1 Created at ... [Delete] [Delete and Lock User]

-- coding: utf-8 --

def findMinAndMax(L): if not isinstance(L,list): raise TypeError('您输入的参数不是列表类型奥,请仔细检查奥!') if len(L)==0: print(None,None) else: min1=min(L) max1=max(L) print(min1, max1)

print(findMinAndMax([])) print(findMinAndMax([1,2,3,6,9])) print(findMinAndMax(56))

jlyybz

#2 Created at ... [Delete] [Delete and Lock User]

没发现你用到迭代啊? 难道max 和 min 方法 就能代表你使用了迭代?

新手问问,大神勿喷

郑男6

#3 Created at ... [Delete] [Delete and Lock User]

楼上你是对的,我没有用到迭代。for循环是一种迭代的方式,不过我觉得用max,min函数更方便些。


  • 1

Reply