Python_求列表s=[]求 元素个数,最大值,最小值,元素和,平均值

#编写程序,求列表s=[]求 元素个数,最大值,最小值,元素和,平均值
def choose(s):
    sum = 0
    all = 0
    maxnum = max(s)
    minnum = min(s)
    for i in s:
        sum = sum + 1 #元素个数
        all = all + i
    average = all / sum
    print(str("元素个数{0},最大值{1},最小值{2},元素和{3},平均值{4}").format(sum, maxnum, minnum, all, average))
def main():
    s = [9,7,8,3,2,1,55,6]
    choose(s)
main()


> PS:本文原创首发于公众号「让我遇见相似的灵魂」,回复关键字获取数十本程序员经典电子书。


你可能感兴趣的:(#,python_经典习题)