如何打印以下空的倒置图案

How to print following empty up side down pattern

我正在尝试打印以下模式,但无法构建逻辑

我的代码:

for i in range(1,row+1):
    if i == 1:
        print(row * '* ')
    elif i<row:
        print( '* ' + ((row - 3) * 2) * ' ' + '*')
        row = row - 1
    else:
        print('*')

预期输出:

* * * * * * * *
*           *
*         *
*       *
*     *
*   *
* *
*

但是我的代码输出异常:

* * * * * * * * 
*           *
*         *  
*       *    
*
*
*
*
row=10
for i in range(1,row):
    if i == 1:
        print(row * '* ')
    elif i < row:
        print('* ' + (row-2)*2 * ' ' + '*')
        row = row-1
    elif i > row-2:
        print('* ' + (row - 2) * 2 * ' ' + '*')
        row = row - 1

输出:

* * * * * * * * * * 
*                 *
*               *
*             *
*           *
*         *
*       *
*     *
*   *

Process finished with exit code 0

希望对您有所帮助

import math

row = 8;
for i in range(1,row+1):
    if i == 1:
        print(row * '* ')
    elif i<(row * row) / (math.pi / math.sqrt(7)):
        print( '* ' + ((row - 3) * 2) * ' ' + '*')
        row = row - 1
    else:
        print('*')

输出:

* * * * * * * * 
*           *
*         *
*       *
*     *
*   *
* *
*

@stacker 的回答很巧妙,但在数学上有点矫枉过正。这也应该可以解决问题:

row = 8
print(row * '* ')
for i in range(1,row - 1):
    rowlength = (row - i) * 2 - 3
    print('*', end='')
    print(rowlength * ' ', end='')
    print('*')
print('*')