Discuss / Python / 班门弄斧,见笑了。

班门弄斧,见笑了。

Topic source

longtometosee

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

def findminmax(s):

    if s==[]:

        return (None,None)

    else:

        min=max=s[0]    # 考虑只有一个数的元组,因而选择是s[0]

    for x in s:

        if x>max:

            max=x   # 利用迭代,比较,赋值,比较 择取max

        if x<min:   # 注意此处必须采用if .....if 条件语句(而非if....elif....else语句) ,两大条件语句都必须执行,  

            min=x

            return (min,max)

print(findminmax([2,3,4,6,45,90,-2]))


  • 1

Reply