求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)
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!的和
本文链接:https://www.haomeiwen.com/subject/vzefvftx.html
网友评论