入门小菜鸟的学习笔记,希望大佬们帮忙纠错啦~侵权立删。
解法一:
s = 1
A = []
for i in range(2,21):
s = s * i
A.append(s)
print(sum(A))
运行结果:
解法二:
s = 0;t = 1
for n in range(2,21):
t *= n
s += t
print(s)
运行结果:
解法三:
list1 = range(2,21)
def mul(x):
r = 1
for i in range(1,x+1):
r *= i
return r
list1 = list(map(mul,list1))
sum(list1)
运行结果:
解法四:
s = 0
def mul(n):
if n == 1:
return 1
return n*mul(n-1)
for i in range(2,21):
a = mul(i)
s += a
print(s)
运行结果:
个人学习笔记,仅供参考,如有错误,请多指正。