打印空心等边三角python
时间: 2023-09-02 14:15:40 浏览: 77
viple打印空心三角形
以下是打印空心等边三角形的Python代码:
```python
rows = int(input("请输入行数:"))
for i in range(1, rows+1):
for j in range(i, rows):
print(" ", end="")
for k in range(1, 2*i):
if k == 1 or k == 2*i-1 or i == rows:
print("*", end="")
else:
print(" ", end="")
print()
```
运行结果:
```
请输入行数:5
*
* *
* *
* *
*********
```
阅读全文