缩小箱子尺寸

时间:2019-06-17 19:42:57

标签: python

我遇到的问题是,我应该在python中制作一个框,该框的大小会不断减小,直到达到零为止。我可以把盒子做得很好,但是我不确定如何缩小它。

box_size=input("box_size:" )
box_size=int(box_size)
for row in range(box_size):
    for col in range(box_size*2):
     print('*',end='')
    print()

1 个答案:

答案 0 :(得分:1)

您可以创建一个外部for循环,该循环从Wrap( children: <Widget>[ Container( color: Colors.red, child: IntrinsicWidth( child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: <Widget>[ Container( color: Colors.black, height: 200, child: Align( alignment: Alignment.bottomRight, child: Text( "Hello World", style: TextStyle(color: Colors.white), ), ), ), Container( color: Colors.blue, height: 100, child: Align( alignment: Alignment.topRight, child: Text( "Bottom Text Longer Text", style: TextStyle(color: Colors.white), ), ), ), ], ), ), ), ], ) box_size
您还可以使用重载的0来创建*星,而不是最里面的for循环

idx*2

输出看起来像

box_size=input("box_size:" )
box_size=int(box_size)

#Outer for loop which goes from box_size to 0
for idx in range(box_size,0,-1):
    #Use the size to print the box
    for row in range(idx):
        #Using overloaded multiplication to create idx*2 *
        print('*'*idx*2,end='')
        print()
    print()