小菜鸟的python进阶之路 ------- for循环打印四种形式的星星

打印四个角的星星

1.

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

i = 1
while i <= 5:
    j = 1
    while j <= i:
        print("*",end='')
        j += 1
    print()
    i += 1

2.

 

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

i = 5
while i >= 0:
    j = 1
    while j <= i:
        print("*",end='')
        j += 1
    print()
    i -= 1

3.
    *
   **
  ***
 ****
*****

while i <= 5:
    j = 1
    while j <= (5 - i):
        print(" ",end='')
        j += 1
    while (j >(5-i) and j <= 5):
        print("*",end='')
        j += 1
    print()
    i += 1

4.
*****
 ****
  ***
   **
    *

i = 1
while i <= 5:
    j = 1
    while j < i:
        print(" ",end='')
        j += 1
    while j >= i and j <= 5:
        print("*",end='')
        j += 1
    print()
    i += 1

你可能感兴趣的:(小菜鸟的python进阶之路,打印四个角的星星)