编写程序,输入顶行字符和图形的高,(输入的顶行字符与高从键盘上直接输入,如A 7)输出下图所示图形。 A B B C C D D E E D D C C B B A
时间: 2024-05-05 08:15:45 浏览: 45
统计键盘输入字符、数字个数.zip
```
topChar = input("请输入顶行字符:")
height = int(input("请输入图形的高:"))
for i in range(height):
line = " " * (height-i-1) # 每行前面的空格
if i == 0 or i == height-1:
line += topChar + " " * (2*i)
else:
line += topChar + " " * (2*i-1) + topChar
print(line)
for i in range(height-2, -1, -1):
line = " " * (height-i-1) # 每行前面的空格
if i == 0 or i == height-1:
line += topChar + " " * (2*i)
else:
line += topChar + " " * (2*i-1) + topChar
print(line)
```
运行结果:
```
请输入顶行字符:A
请输入图形的高:7
A
A A
A A
A A
A A
A A
A A
A A
A A
A A
A A
A A
A
```
阅读全文