python求10个数的平均数的方法:使用sun求平均数,代码为【L=[1,2,3,4,5,6,7,8,9,10],a=sum(L)/len(L),print("avge is:", round(a,3) )】。

本教程操作环境:windows7系统、python3.9版,DELL G3电脑。
python求10个数的平均数的方法:
一,已知十个数,求平均数。
L=[1,2,3,4,5,6,7,8,9,10]
a=sum(L)/len(L)
print("avge is:", round(a,3) )运行结果:
立即学习“Python免费学习笔记(深入)”;
avge is: 5.5
二,设置输入个数,求平均数
n = int(input("请输入所求平均数的个数: "))
l = []
for i in range(0, n):
k = int(input("请输入数值: "))
l.append(k)
avg = sum(l) / n
print("这 %d 个数的平均数是:" % n, round(avg, 3))运行结果:
立即学习“Python免费学习笔记(深入)”;
请输入所求平均数的个数: 3 请输入数值: 1 请输入数值: 2 请输入数值: 3 这 3 个数的平均数是: 2.0
相关免费学习推荐:python视频教程
以上就是python如何求10个数的平均数的详细内容,更多请关注php中文网其它相关文章!
python怎么学习?python怎么入门?python在哪学?python怎么学才快?不用担心,这里为大家提供了python速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号