019. 求1+2!+3!+4!+...20!的和

求1+2!+3!+4!+...20!的和。

def factorial_sum(num):
if num == 1:
return 1
else:
return (num * factorial_sum(num-1))
res = 0

for i in range(1,21):
res += factorial_sum(i)
if i == 20:
print(i,end='!=')
else:
print(i,end='!+')
print(res)

你可能感兴趣的:(019. 求1+2!+3!+4!+...20!的和)