python输入一系列数字,并求和与求平均数

如题所述

    def exercise():

            count=0

            total=0

            while True:

                    s=input('请输入数字后按回车键,输入字母e结束:')

                    if s=='e':break

                    if s=='' or not s.isdigit():continue

                    total+=int(s)

                    count+=1

            print('你输入了',count,'个数字,总和为',total,'平均数是',total/count)

温馨提示:答案为网友推荐,仅供参考
相似回答