阶乘求和_
作者:互联网
# 方法一
def sum(m, sum_result=0):
if m == 0:
return sum_result
factorial = 1
for i in range(1, m + 1): # 这个循环可以计算m!
factorial = factorial * i
return sum(m - 1, sum_result + factorial)
print(sum(int(input())))
# 方法二
sums = 0
for i in range(1, int(input()) + 1):
s = 1
for j in range(1, i + 1):
s = s * j
# print(s)
sums += s
print(sums)
# 方法三
print(sum([__import__('math').factorial(i) for i in range(1, int(input())+1)]))
# list= [math.factorial(i) for i in range(1, int(input()) + 1)]
# print(list)
标签:int,求和,sum,print,range,factorial,阶乘,input 来源: https://blog.csdn.net/Zzzzzz_m/article/details/122398112