求s=1!+2!+...+n!
时间: 2023-12-01 21:43:06 浏览: 74
求!+!+!++n!-过程和函数
以下是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)
```
阅读全文