1 方法一: 2 s = 1 3 sum = 0 4 for i in range(1,6): 5 s = s*i 6 sum += s 7 print(s) 8 print(sum)
1 方法二:效率低,每次都要重新算k 2 3 n = 0 4 for i in range(1,6): 5 k = 1 6 for j in range(1, i + 1): 7 k = k * j 8 n = n + k 9 print(n)