时间:2022-11-16 09:15:13 | 栏目:Python代码 | 点击:次
ls=[4,9,19,8,391,39,9,283,45] sum(ls) average=sum(ls)/len(ls) print('累加值',sum(ls),'平均值',average)
Python 环境:Python 2.7.12 x64
IDE:Wing IDE Professional 5.1.12-1
题目:求数组元素的平均值
#求数组元素的平均值 a=[1,4,8,10,12] b=len(a) sum=0 print "数组长度为:",b for i in a: sum=sum+i print "均值为:",sum/b