如何利用while语句根据用户输入要求打印菱形图案

需求:如何利用while语句根据用户输入要求打印菱形图案

diamond.py代码如下:

x=int(input('Please input number: '))

i=1

j=1

while i<=x:

    j=1

    while j<=x-i :

        print(' ',end='')

        j+=1

    while j<=x:

        print('* ',end='')

        j+=1

    print()

    i+=1

i=1

while i<=x-1:

    j=1

    while j<=i :

        print(' ',end='')

        j+=1

    while j<=x:

        print('* ',end='')

        j+=1

    print()

    i+=1

 输出结果如下:

原文地址:https://www.cnblogs.com/xiaolichaoren/p/5793184.html