求s=1!+2!+...+n!
时间: 2023-12-01 16:43:06 浏览: 70
求1+2+…+n.md
以下是Python代码,用于计算s=1!+2!+...+n!:
```python
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
n = int(input("请输入一个正整数n:"))
sum = 0
for i in range(1, n+1):
m = factorial(i)
sum += m
print("s的值为:", sum)
```
阅读全文