Discuss / Python / 今天的作业

今天的作业

Topic source

蓬蓬哇

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

def findMinAndMax(L):

    if len(L)==0:

        return (None, None)

    else:

        max=min=L[0]

        for x in L:

            if x>max:

                max=x

            if x<min:

                min=x

        return(min,max)

犇淼2020

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

缺少遍历的过程:

def findMinandmax(L):    if not isinstance(L,(list)):        return '请输入一个list'    if len(L)==0:        return (None,None)    else:        Max = Min = L[0]        for i in L:            if i>=Max:                Max = i        for  ma in L:            if ma<= Min:                Min = ma        return (Min,Max)print(findMinandmax([2,4,6]))

  • 1

Reply