python不定長パラメータを使用して入力値の和、平均値、最大値、最小値を求める

1186 ワード

'''
    @author:xianyt
    @vertion:python3
    @date:2018/7/25
    @function:    ,       ,   ,   ,   (         )
        :
        1)    ,     
        2)             ,    
        3)        ,(    :          ,      。        )
        4)      ,       
'''
def numFun(*numbers):
    if numbers:
        firstList = numbers[0]
        sumnum = sum(firstList)
        maxnum = max(firstList)
        minnum = min(firstList)
        avernum = sum(firstList)/len(firstList)
        '''   #         
        max = min = firstList[0]
        for x in firstList:
            sum += x
            if max <= x :
                max = x;
            if min >= x:
                min = x;
        aver = sum / len(firstList)
        '''
        print("    :", firstList)
        print('  :', sumnum, '   ', avernum, '   ', maxnum, '   ', minnum )


if __name__ == '__main__':
    numbers = input("       ")
    numbers = numbers.split(',')
    for x in range(len(numbers)):
        numbers[x] = int(numbers[x])
    print(numbers)
    numFun(numbers)