c(n): if n==1: return 1 else num=c(10) print( n*c(n-1)
时间: 2023-12-24 20:05:26 浏览: 22
这段代码存在一些问题,可以做如下修改:
```python
def c(n):
if n == 1:
return 1
else:
return n * c(n-1)
num = c(10)
print(num) # 输出3628800
print(5*c(4)) # 输出120
```
首先定义了一个递归函数`c(n)`,用于求n的阶乘。然后在主程序中调用该函数,将结果赋值给变量`num`。最后通过`print()`函数输出`num`的值和`5*c(4)`的值,其中`c(4)`即为4的阶乘,结果为24,再乘以5得到120,与5的阶乘相等。
相关推荐
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![jpg](https://img-home.csdnimg.cn/images/20210720090814.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)