求1到n的阶乘之和python,函数
时间: 2023-04-01 20:01:42 浏览: 132
python 实现阶乘求和
5星 · 资源好评率100%
def factorial(n):
if n == :
return 1
else:
return n * factorial(n-1)
def sum_factorial(n):
sum =
for i in range(1, n+1):
sum += factorial(i)
return sum
print(sum_factorial(5)) # 输出 153
阅读全文