python求平均值小程序

def start():
    print('请输入求平均值的数字,数字之间用逗号隔开\n')
    num = input()
    num1 = num.split(',')
    try:
        while True:
            num1.remove(',')
    except:
        pass
    try:
        r=list(map(float,num1))
        avg=sum(r)/len(r)
        print('平均值:{}'.format(avg))
    except:
        print('\n您输入的值包含非法字符\n')
        start()
        
start()

转载自:https://blog.csdn.net/qq_36552335/article/details/52965841

You may also like...