zoukankan      html  css  js  c++  java
  • 20 sum()函数及自定义函数复习(学习啊)

     1 def func(lst):
     2     sum = 0
     3     avg = 0
     4     for i in range(len(lst)):
     5         sum += lst[i]
     6         avg = sum/len(lst)
     7     return (sum,avg)
     8     # print(sum,avg)
     9 
    10 l = [1,2,3,4,5]
    11 print(func(l))
    12 
    13 2)进阶版
    14 def getMaxMinAvgoflist(list):
    15     Max = max(list)
    16     Min = min(list)
    17     sum = 0.0
    18     for i in range(len(list)):
    19         sum += list[i]
    20         Avg = 1.0*sum/len(list)
    21     print('max:{},min:{},ave:{}'.format(Max,Min,Avg))
    22  # return  (Max,Min,Avg)  # 函数的返回值为元组
    23 
    24 l = []
    25 geshu = int(input('请输入你需要的个数:'))
    26 for i in range(geshu):
    27     temp = input('请输入%d个数:'%(i+1))
    28     temp = float(temp)
    29     l.append(temp)
    30 
    31 getMaxMinAvgoflist(l)
  • 相关阅读:
    js中replace的正则替换
    ios沙盒路径
    Android开源框架
    小知识点
    __NSCFConstantString && __NSPlaceholderDictionary
    iq 格式分析
    C 函数
    Xcode报错
    XMPP Server
    H5网站借鉴
  • 原文地址:https://www.cnblogs.com/reaix/p/12765044.html
Copyright © 2011-2022 走看看