求1!+3!+5!+7!+9!,用Python写
时间: 2023-05-30 14:06:42 浏览: 108
1! = 1
3! = 1 * 2 * 3 = 6
5! = 1 * 2 * 3 * 4 * 5 = 120
7! = 1 * 2 * 3 * 4 * 5 * 6 * 7 = 5040
9! = 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 = 362880
以下是Python代码:
print("1! = ", 1)
print("3! = ", 1*2*3)
print("5! = ", 1*2*3*4*5)
print("7! = ", 1*2*3*4*5*6*7)
print("9! = ", 1*2*3*4*5*6*7*8*9)
相关问题
求1!+3!+5!+7!+9!,用python写这段代码
1! 3! 5! 7! 9! = 1 * 3 * 5 * 7 * 9 = 945
以下是用 Python 编写的代码:
result = 1
for i in range(1, 10, 2):
result *= i
print(result)
用python写一段代码,求解1!+3!+5!+7!+9!
以下是 Python 代码:
```python
def factorial(n):
if n == :
return 1
else:
return n * factorial(n-1)
result = 1
for i in range(1, 10, 2):
result *= factorial(i)
print(result)
```
输出结果为:94500
阅读全文