python输出倒立杨辉三角
时间: 2024-01-18 13:18:05 浏览: 123
用Python输出一个杨辉三角的例子
以下是Python输出倒立杨辉三角的代码示例:
```python
def print_inverted_pascal_triangle(n):
triangle = []
for i in range(n):
row = [1] * (i + 1)
triangle.append(row)
for j in range(1, i):
triangle[i][j] = triangle[i-1][j-1] + triangle[i-1][j]
for row in reversed(triangle):
print(' '.join(map(str, row)))
# 示例调用
print_inverted_pascal_triangle(5)
```
输出结果为:
```
1 4 6 4 1
1 3 3 1
1 2 1
1 1
1
```
阅读全文