📜  如何使用循环在 python 中求平均值 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:26.751000             🧑  作者: Mango

代码示例1
list = input('Input a list of numbers separated by comma then space:\n ')
try:
    list = list.split(', ')
    sum = 0
    
    for number in list:
        sum = int(number) + sum

    avg = sum / len(list)
    print('The average of the numbers you entered is: ', avg)
except ValueError:
    print('Please enter a list of number separated by a comma and space only')