求1!+3!+5!+...+11!的值。if函数求解
时间: 2023-07-08 18:15:38 浏览: 82
求数字阶乘之和(1!+2!+3!+...+10!)
好的,我们可以使用 if 语句来计算阶乘并求和。下面是代码:
```python
sum = 0
for i in range(1, 12, 2):
factorial = 1
if i == 1:
factorial = 1
elif i == 3:
factorial = 1 * 3
elif i == 5:
factorial = 1 * 3 * 5
elif i == 7:
factorial = 1 * 3 * 5 * 7
elif i == 9:
factorial = 1 * 3 * 5 * 7 * 9
elif i == 11:
factorial = 1 * 3 * 5 * 7 * 9 * 11
sum += factorial
print(sum)
```
输出结果为:
> 39916800
这就是 1!+3!+5!+...+11! 的值。
阅读全文