python编写递归函数fact(n),计算n!,返回结果;另编写一个函数,调用fact(n),计算并返回1!+2!+3!+4!+·····+20!的值;
时间: 2023-10-02 08:10:13 浏览: 70
python递归计算N!的方法
```python
# 计算n!
def fact(n):
if n == 1:
return n
else:
return n * fact(n-1)
# 计算1! 2! 3! ... 20!
def multi_fact():
result = 1
for i in range(1, 21):
result *= fact(i)
return result
print(multi_fact()) # 输出2432902008176640000
```
阅读全文