Home  >  Article  >  Backend Development  >  How to find the average of 10 numbers in python

How to find the average of 10 numbers in python

coldplay.xixi
coldplay.xixiOriginal
2021-03-11 15:01:5028242browse

Python method to find the average of 10 numbers: use sun to find the average, the code is [L=[1,2,3,4,5,6,7,8,9,10], a=sum(L)/len(L), print("avge is:", round(a,3))].

How to find the average of 10 numbers in python

The operating environment of this tutorial: Windows 7 system, python version 3.9, DELL G3 computer.

Python method to find the average of 10 numbers:

1. Given ten numbers, find the average.

L=[1,2,3,4,5,6,7,8,9,10]
a=sum(L)/len(L)
print("avge is:", round(a,3) )

Run result:

avge is: 5.5

Second, set the number of inputs and find the average

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))

Run result:

请输入所求平均数的个数: 3
请输入数值: 1
请输入数值: 2
请输入数值: 3
这 3 个数的平均数是: 2.0

Related free learning recommendations: python video tutorial

The above is the detailed content of How to find the average of 10 numbers in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn