python1到9的阶乘代码
时间: 2024-05-11 18:16:25 浏览: 109
n的阶乘 python代码
下面是Python中1-9的阶乘代码:
```python
# 阶乘函数
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
# 计算1-9的阶乘
for i in range(1, 10):
print("{}! = {}".format(i, factorial(i)))
```
阅读全文