Discuss / Python / 打卡,作业

打卡,作业

Topic source

人玉匆花

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

def findMinAndMax(L):

    if L == []:

        return (None,None)

    max = L[0]

    min = L[0]

    for l in L:

        if l > max:

            max = l

        if l < min:

            min = l

    return (min,max)

**PS:**一开始陷入了循环中变量取值的死胡同,想到循环递归的方式,两两比较。

最初的变量取值,完全可以在循环外进行取值,然后通过循环,动态为所需变量赋值。


  • 1

Reply