1到n的阶乘相加
l=1 # 1到n阶乘,相加 s=0 n=int(input('n=')) for i in range(1,n+1): l *= i s += l print('num=',l,'sum=',s)
求每次输入的数字的算术平均值
c = 0 ############求每次输入的数字的算术平均值 s = 0 while True: a = input('>>') if not a: break a = int(a) c += 1 s += a avg = s / c print(avg)