python基础练习题09

在控制台连续输出五行*,每一行星号的数量依次递增

row=1
while row<=5:
    col=1
    while col<=row:
        print('*',end='')
        col+=1
    print()
    row+=1

# 输出结果
# *
# **
# ***
# ****
# *****

02:

row=5
while row>=1:
    col=1
    while col<=row:
        print('*',end='')
        col+=1
    print('')
    row-=1

# 输出结果
# *****
# ****
# ***
# **
# *

03:

row=1
while row<=5:
    col=1
    space=1
    while col <=5-row:
        print(' ',end='')
        col+=1
    while space<=row:
        print('*',end='')
        space+=1
    print('')
    row+=1
# 输出结果:
#
#     *
#    **
#   ***
#  ****
# ***

04:

row=5
while row>=1:
    col=1
    space=1
    while col<=5-row:
        print('',end='')
        col+=1
    while space<=row:
        print('*',end='')
        space+=1
    print('')
    row -= 1
# 输出结果:
# *****
#  ****
#   ***
#    **
#     *
我是kelly-凯莉 每天努力一点点,幸运就多一点点
原文地址:https://www.cnblogs.com/kelly11/p/12125512.html