【发布时间】:2022-10-05 06:23:29
【问题描述】:
我为一个空心矩形创建了一个代码,但我无法在矩形内放置一个直立的等腰金字塔。谁能帮助我如何在矩形内挤压金字塔的代码? 这是它应该看起来的样子 my code output vs. the right way
#here are the inputs:
b = height of the rectangle
2*b-1 = width of the rectangle
a = height of the triangle
这是我的代码: 这个矩形的输出,下面是一个金字塔,这不是我想要的。
b = int(input(\'Enter b: \'))
a = int(input(\'Enter a:\\n\'))
horizontal = b
vertical = 2*b-1
height = (a)
#for the rectangle
for i in range (horizontal):
for j in range(vertical):
if(i == 0 or i == horizontal - 1 or j == 0 or j == vertical - 1):
print(\'b\', end = \'\')
else:
print(\' \', end = \'\')
print()
#for the pyramid
for i in range (1, height-1):
j = height - i
print(\' \'*j+(2*i-1)*\'a\')
-
@MagnusO_O,谢谢。我已经编辑了我的问题,请随时提供帮助!
标签: python python-3.x helper