def factorial_sum(n): sum = 0 factorial = 1 for i in range(1, n+1): factorial *= i sum += factorial return sum
时间: 2023-05-14 16:05:04 浏览: 120
SNTGT_number_Factorial_prime_
这是一个计算阶乘和的函数,但是代码有误,应该是for i in range(1, n+1)。修正后的代码如下:
def factorial_sum(n):
sum = 0
factorial = 1
for i in range(1, n+1):
factorial *= i
sum += factorial
return sum
如果调用factorial_sum(5),则返回153。
阅读全文