python学习笔记------实现四种星星打印 - Go语言中文社区

python学习笔记------实现四种星星打印


第一种:

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

代码:

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

运行:

第二种:

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

代码:

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

运行:

第三种:

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

代码:

for i in range(6):
    print(' '*(6-i),end='')
    print('*'* i)

运行:

或者:

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

运行:

第四种:

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

代码:

for i in range(5):
    print(' '*i,end='*')
    print('*'*(4-i))

运行:

或者:

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

运行:

版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/noflag/article/details/93923642
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2020-03-01 23:16:34
  • 阅读 ( 945 )
  • 分类:

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢