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

  • 相关阅读:
    Hbase集群部署及shell操作
    sqoop部署与使用
    azkaban部署
    Hive入门操作
    Hive部署
    MapReduce过程详解(基于hadoop2.x架构)
    MapReduce编程中常用的字符操作
    【图文详解】深入HDFS原理
    vue项目跨域问题的解决:vue-cli 开启代理
    beego框架入门(2)
  • 原文地址:https://www.cnblogs.com/hm-hx-ldy/p/8260906.html
Copyright © 2011-2022 走看看