求1!+2!+3!+4!+5!+6!+7!+8!+9!+10!使用Python
时间: 2023-11-25 19:06:07 浏览: 160
python 求1+2!+3!+...+20!的和 (示例)
5星 · 资源好评率100%
以下是Python代码,用于计算1!+2!+3!+4!+5!+6!+7!+8!+9!+10!的值:
```python
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
sum = 0
for i in range(1, 11):
sum += factorial(i)
print("1!+2!+3!+4!+5!+6!+7!+8!+9!+10!的值为:", sum)
```
阅读全文