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

How to find the average of 10 numbers in python

coldplay.xixi
Release: 2023-01-03 09:29:19
Original
28275 people have browsed it

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) )
Copy after login

Run result:

avge is: 5.5
Copy after login

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))
Copy after login

Run result:

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template