python 使用循环结构完成共九行,右半边为棱形的*图案输出
时间: 2023-05-16 15:06:17 浏览: 158
python的循环结构
以下是 Python 代码实现:
```
n = 5
for i in range(n):
for j in range(n-i-1):
print(" ", end="")
for j in range(i+1):
print("* ", end="")
print()
for i in range(n-1):
for j in range(i+1):
print(" ", end="")
for j in range(n-i-1):
print("* ", end="")
print()
```
输出结果为:
```
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
```
阅读全文