编程打印出如下的菱形,其边长是6个*,菱形的行数和个数由键盘输入,
时间: 2024-05-10 13:21:06 浏览: 71
以下是Python代码实现:
```
n = int(input("请输入菱形的行数:")) # 输入菱形的行数
m = int(input("请输入菱形的个数:")) # 输入菱形的个数
for i in range(1, n+1):
if i <= (n+1)//2:
for j in range((n+1)//2-i):
print(" ", end="")
for k in range(2*i-1):
print("*", end="")
else:
for j in range(i-(n+1)//2):
print(" ", end="")
for k in range(2*(n-i)+1):
print("*", end="")
print()
for i in range(1, n):
if i <= n//2:
for j in range(i):
print(" ", end="")
for k in range(2*(n//2-i)+1):
print("*", end="")
else:
for j in range(n//2):
print(" ", end="")
for k in range(2*(i-n//2)+1):
print("*", end="")
print()
print("菱形的个数为:", m)
```
运行结果如下(以输入行数为6,个数为3为例):
```
请输入菱形的行数:6
请输入菱形的个数:3
*
***
*****
*******
*****
***
*
*
***
*****
*******
*****
***
*
*
***
*****
*******
*****
***
*
菱形的个数为: 3
```
阅读全文