从键盘输入一个列表,计算输出列表元素的平均值。
示例如下:
输入
[2,3,5,7]
输出
平均值为: 4.25
实施代码:
def mean( numlist): s=0.0 for num in numlist: = +num return/len( numlist) #请输入一个列表: ls=eval( input("")) print("平均值为:",mean(ls))
结果输出:
[2,3,5,7] 平均值为: 4.25
上一篇:python指针读取函数seek()的使用方法
下一篇:怎样使用python里的input函数