Python 输入数字直到输入0,然后获取数字的算术平均值,0除外

Python 输入数字直到输入0,然后获取数字的算术平均值,0除外,python,floating-point,mean,Python,Floating Point,Mean,它应该是这样的: 输入: 2 3.5 4.4 0 输出: 3.13 你应该 将所有非0的输入添加到列表中 计算平均数 此代码可执行此操作,例如: number = [] #| List to hold the numbers while True: # Repeat action as many times as needed until there is a break (0) a = float(input()) # Read input number if a =

它应该是这样的:

输入:

2
3.5
4.4
0
输出:

3.13
你应该

将所有非0的输入添加到列表中 计算平均数 此代码可执行此操作,例如:

number = []  #| List to hold the numbers
while True:  # Repeat action as many times as needed until there is a break (0)
    a = float(input())  # Read input number
    if a == 0:  
        break  # Stop remembering numbers
    number.append(a)  # If not 0, add number to the list
print(sum(number)/len(number))  # print the average value

你试过什么,到底有什么问题?我的知识真的很有限,但这就是我迄今为止所做的。我已经要求用户输入一个浮点值,当该值大于0时,我要求他输入另一个,然后我打印了输入,所以只打印了0问题,以给出一个答案。因此,这不是一项代码编写或教程服务,您需要清楚地表达特定的问题。2+3.5+4.4的平均值不是3.13,而是3.3,请考虑添加一些描述您的解决方案的文本,以便OP和其他人可以从中学习。