1!+2!+……+n!python
时间: 2023-11-12 22:08:12 浏览: 85
1!+2!+..n!
可以使用循环来计算1!+2!+……+n!,具体实现如下:
```python
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
def sum_of_factorials(n):
sum = 0
for i in range(1, n+1):
sum += factorial(i)
return sum
n = int(input("请输入n的值:"))
print("1!+2!+……+n!的和为:", sum_of_factorials(n))
```
阅读全文