打印空心等边三角python
时间: 2023-09-02 14:15:40 浏览: 78
以下是打印空心等边三角形的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
*
* *
* *
* *
*********
```
相关问题
python打印空心等边三角形
以下是 Python 打印空心等边三角形的代码:
```
rows = int(input("请输入行数:"))
for i in range(rows):
for j in range(rows - i - 1):
print(" ", end="")
for j in range(2 * i + 1):
if j == 0 or j == 2 * i or i == rows - 1:
print("*", end="")
else:
print(" ", end="")
print()
```
这段代码可以让 Python 打印出指定行数的空心等边三角形。
Python 打印空心等腰三角
以下是Python打印空心等腰三角形的代码:
```python
n = int(input("请输入要打印的行数:"))
for i in range(1, n+1):
for j in range(1, n-i+1):
print(" ", end="")
for k in range(1, 2*i):
if i == n or k == 1 or k == 2*i-1:
print("*", end="")
else:
print(" ", end="")
print("")
```
阅读全文