1.编写一个函数cacluate,可以接收任意个数,返回的是一个元组,其中元组的第一个值为所有参数的平均值,第二个值是大于平均值的所有数。
def cacluate (*args): print args,type(args); avg=sum(args)/len(args); print avg; list=[]; for i in args: if i>avg: list.append(i); tuple=(avg,list); return tuple; print cacluate(1,2,3,4,5);
运行结果:
(1, 2, 3, 4, 5) <type 'tuple'> 3 (3, [4, 5])
标签:练习题,args,tuple,python,练习,list,cacluate,print,avg From: https://www.cnblogs.com/joyware/p/16922150.html