码迷,mamicode.com
首页 > 其他好文 > 详细

if与while相互嵌套,菱形*的实现.py

时间:2018-01-10 22:46:57      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:row   pos   odi   实现   log   utf-8   gpo   int   nbsp   

"""
    *        
   * *       
  * * *      
 * * * *     
* * * * *    
 * * * *     
  * * *      
   * *       
    *        
"""

# -*-coding:utf-8-*-

# i = 0
#
# while i < 9:
#
#     if i < 5:
#
#         print(" "*(4-i),"* "*(i+1))
#
#     else:
#
#         print(" "*(i-4),"* "*(9-i))
#
#     i += 1


"""
    *        1 4 1
   * *       2 3 2
  * * *      3 2 3
 * * * *     4 1 4
* * * * *    5 0 5
 * * * *     6 1 4
  * * *      7 2 3
   * *       8 3 2
    *        9 4 1
"""

row = 1

 

while row <= 9:

    if row <= 5:

        print(" "*(5-row),end="")

        col = 1

        while col <= row:


            print("* ",end="")

            col += 1

        print("")

    else:

        print(" "*(row-5),end="")

        col = 1

        while col <= (10 -row):

 

            print("* ",end="")


            col += 1
        print("")

    row += 1

if与while相互嵌套,菱形*的实现.py

标签:row   pos   odi   实现   log   utf-8   gpo   int   nbsp   

原文地址:https://www.cnblogs.com/hm-hx-ldy/p/8260906.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!