如何在python中找到均值

时间:2019-02-13 06:11:56

标签: python python-3.x loops

如何在python中查找均值

t = int(input("How many marks do you want entered" ))
g = 0

for i in range(t):
    c = int(input('what is your mark'))
g = c/t 
print(g)

我需要找到输入到c,t次的所有数字的平均值

2 个答案:

答案 0 :(得分:2)

您需要跟踪所有标记。像这样:

t = int(input("How many marks do you want entered" ))
g = 0

marks = []
for i in range(t):
    marks.append(int(input('what is your mark')))
g = sum(marks)/t 
print(g)

答案 1 :(得分:1)

使用以下代码:

t=int(input("How many marks do you want entered" ))
g=0
c=0
for i in range(t):
    c += int(input('what is your mark'))
g = c/t 
print(g)