用循环,并用*****打出一个棱形
时间: 2023-09-02 14:05:42 浏览: 72
javafor循环打出菱形
```
*
***
*****
*******
*****
***
*
```
代码实现:
```python
size = 4 # 棱形大小
for i in range(size):
for j in range(size - i):
print(" ", end="")
for j in range(2 * i + 1):
print("*", end="")
print()
for i in range(size - 2, -1, -1):
for j in range(size - i):
print(" ", end="")
for j in range(2 * i + 1):
print("*", end="")
print()
```
输出结果:
```
*
***
*****
*******
*****
***
*
```
阅读全文