zoukankan      html  css  js  c++  java
  • if与while相互嵌套,菱形*的实现.py

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

    # -*-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

  • 相关阅读:
    URL
    B/S架构
    SQL查询语句
    SQL-Delete语句
    SQL运算符
    SQL结构查询语言
    SQL数据库数据类型详解
    标准文档流
    CSS
    字体样式
  • 原文地址:https://www.cnblogs.com/hm-hx-ldy/p/8260906.html
Copyright © 2011-2022 走看看