python编程—在控制台连续输出五行*,每一行星号数量一次递增

需要最终在屏幕显示结果为:
1、

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

代码如下:

"""
# _*_coding:utf-8_*_
Name:xing.py
Date:1/14/19
Author:westos-sql
Connect:[email protected]
Desc:...
"""
row = 1
while row <= 5:
    col = 1
    while col <= row:
        print('*',end='')
        col += 1
    print('')
    row += 1

在这里插入图片描述

结果如下:
在这里插入图片描述

2、

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

代码如下:

"""
# _*_coding:utf-8_*_
Name:xing.py
Date:1/14/19
Author:westos-sql
Connect:[email protected]
Desc:...
"""

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

在这里插入图片描述

执行结果如下:
在这里插入图片描述

3、

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

代码如下:

"""
# _*_coding:utf-8_*_
Name:xing.py
Date:1/14/19
Author:westos-sql
Connect:[email protected]
Desc:...
"""

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

在这里插入图片描述

执行结果如下:
在这里插入图片描述

4、

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

代码如下:

"""
# _*_coding:utf-8_*_
Name:xing.py
Date:1/14/19
Author:westos-sql
Connect:[email protected]
Desc:...
"""

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

在这里插入图片描述

执行结果如下:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43314056/article/details/86485070