python双重循环打印下图所示菱形不用import * *** ***** ******* ***** *** *
时间: 2023-12-24 20:03:10 浏览: 54
以下是使用双重循环打印菱形的Python代码:
```python
rows = int(input("请输入菱形边长:"))
# 打印菱形上半部分
for i in range(rows):
for j in range(rows - i):
print(" ", end="")
for k in range(2 * i - 1):
if k == 0 or k == 2 * i - 2:
print("*", end="")
else:
print(" ", end="")
print()
# 打印菱形的下半部分
for i in range(rows-2, 0, -1):
for j in range(rows - i):
print(" ", end="")
for k in range(2 * i - 1):
if k == 0 or k == 2 * i - 2:
print("*", end="")
else:
print(" ", end="")
print()
```
运行结果如下:
```
*
***
*****
*******
*****
***
*
```
阅读全文