输入n,分别用*输出边长为n的实心菱形和空心菱形
时间: 2024-02-26 14:59:10 浏览: 91
输出空心或实心菱形
好的,我可以帮你写一个Python程序来实现这个功能。以下是代码:
```python
n = int(input("请输入边长n:"))
# 输出实心菱形
for i in range(n):
print(" " * (n-i-1) + "*" * (2*i+1))
for i in range(n-2,-1,-1):
print(" " * (n-i-1) + "*" * (2*i+1))
# 输出空心菱形
for i in range(n):
if i == 0:
print(" " * (n-i-1) + "*")
else:
print(" " * (n-i-1) + "*" + " " * (2*i-1) + "*")
for i in range(n-2,-1,-1):
if i == 0:
print(" " * (n-i-1) + "*")
else:
print(" " * (n-i-1) + "*" + " " * (2*i-1) + "*")
```
你可以运行这段代码并输入边长n来查看输出结果。希望能对你有所帮助!
阅读全文