经典题型-打印小星星(python)

# *
# * *
# * * *
# * * * *
# * * * * *

x = 0
while x < 5:
    x += 1
    # 每次循环需要给y赋值0.清空y中存储的值
    y = 0
    while y < x:
        print('*', end='')
        y += 1
    print('')
# *
# * *
# * * *
# * * * *
# * * * * *
# * * * *
# * * *
# * *
# *
row = 0
while row < 5:
    row += 1
    col = 0
    while col < row:
        col += 1
        print('*', end='')
    print('')
while 5<= row < 9:
    row += 1
    col = 9
    while col >= row:
        col -= 1
        print('*', end='')
    print('')

 

posted @ 2018-03-13 22:51  沈强-1201  阅读(1314)  评论(0编辑  收藏  举报