编写计算计算1!+2!+3!+4!+…n!
时间: 2023-05-30 19:03:33 浏览: 66
编程实现计算:1!+2!+3!+……+N!的值,要求定义并调用函数计算N!。
5星 · 资源好评率100%
以下是Python代码实现:
```python
n = int(input("请输入n的值:"))
factorial = 1
for i in range(1, n+1):
factorial *= i
print(f"{i}! = {factorial}")
```
输出结果:
```
请输入n的值:5
1! = 1
2! = 2
3! = 6
4! = 24
5! = 120
```
阅读全文