Python循环输出各种图案——你未曾见过的拍案叫绝

前言

以前水的一篇文章:C语言循环输出各种 * 组成的图形 今天用Python去复现,发现可以更加简单高效,就顺便再水一篇文章吧,23333~~嗝 话不多说 直接贴国光精简后的代码

直角三角形一

图案

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

代码

Python
for i in range(11):
    print("* " * i)

直角三角形二

图案

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

代码

Python
for i in range(10,0,-1):
    print("* " * i)

直角三角形三

图案

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

代码

Python
for i in range(11):
    print("  " * (10-i) + "* " * i)

直角三角形四

图案

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

代码

Python
for i in range(10,0,-1):
    print("  " * (10-i) + "* " * i)

直角三角形五

图案

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

代码

Python
for i in range(8):
    print("* " * i)
for i in range(6,0,-1):
    print("* " * i)

直角三角形六

图案

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

代码

Python
for i in range(8):
    print("  " * (7-i) + "* " * i)
for i in range(6,0,-1):
    print("  " * (7-i) + "* " * i)

普通三角形一

图案

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

代码

Python
for i in range(11):
    print(" "*(10-i)+"* "*i)

普通三角形二

图案

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

代码

Python
for i in range(10,0,-1):
    print(" "*(10-i)+"* "*i)

菱形一

图案

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

代码

Python
for i in range(8):
    print(" " * (7-i) + "* " * i)
for i in range(6,0,-1):
    print(" " * (7-i) + "* " * i)

菱形二

图案

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

代码

Python
for i in range(8):
    print("   " * (7-i) + "*     " * i)
for i in range(6,0,-1):
    print("   " * (7-i) + "*     " * i)

平行四边形一

图案

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

代码

Python
for i in range(9):
    print(" " * (8-i) + "* " * 8)

平行四边形二

图案

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

代码

Python
for i in range(9):
    print(" " * i + "* " * 8)

平行四边形三

图案

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

代码

Python
for i in range(9):
    if i == 1 or i == 8:
        print(" " * (8-i) + "* " * 8)
    else:
        print(" " * (8-i) + "* " + "  " * 6 + "*")

特殊图案系列

图案1

                              *
                         *     *
                    *     *     *
               *     *     *     *
          *     *     *     *     *
     *     *     *     *     *     *
*     *     *     *     *     *     *
     *     *     *     *     *     *
          *     *     *     *     *
               *     *     *     *
                    *     *     *
                         *     *
                              *
Python
for i in range(8):
    print("     " * (7-i) + "*     " * i)
for i in range(6,0,-1):
    print("     " * (7-i) + "*     " * i)

图案2

            *
          *     *
        *     *     *
      *     *     *     *
    *     *     *     *     *
  *     *     *     *     *     *
*     *     *     *     *     *     *
  *     *     *     *     *     *
    *     *     *     *     *
      *     *     *     *
        *     *     *
          *     *
            *
Python
for i in range(8):
    print("  " * (7-i) + "*     " * i)
for i in range(6,0,-1):
    print("  " * (7-i) + "*     " * i)

图案3

                              *
                         *  *
                    *  *  *
               *  *  *  *
          *  *  *  *  *
     *  *  *  *  *  *
*  *  *  *  *  *  *
     *  *  *  *  *  *
          *  *  *  *  *
               *  *  *  *
                    *  *  *
                         *  *
                              *
Python
for i in range(8):
    print("     " * (7-i) + "*  " * i)
for i in range(6,0,-1):
    print("     " * (7-i) + "*  " * i)

图案4

  *
    *  *
      *  *  *
        *  *  *  *
          *  *  *  *  *
            *  *  *  *  *  *
              *  *  *  *  *  *  *
            *  *  *  *  *  *
          *  *  *  *  *
        *  *  *  *
      *  *  *
    *  *
  *
Python
for i in range(8):
    print("  " * i + "*  " * i)
for i in range(6,0,-1):
    print("  " * i + "*  " * i)

图案5

                              *
                         *  *   *  *
                    *  *  *       *  *  *
               *  *  *  *           *  *  *  *
          *  *  *  *  *               *  *  *  *  *
     *  *  *  *  *  *                   *  *  *  *  *  *
*  *  *  *  *  *  *                       *  *  *  *  *  *  *
     *  *  *  *  *  *                   *  *  *  *  *  *
          *  *  *  *  *               *  *  *  *  *
               *  *  *  *           *  *  *  *
                    *  *  *       *  *  *
                         *  *   *  *
                              *
Python
for i in range(8):
    print("     " * (7-i) + "*  " * i + "  " * i * 2 + "\b" * 7 + "*  " * i)
for i in range(6,0,-1):
    print("     " * (7-i) + "*  " * i + "  " * i * 2 + "\b" * 7 + "*  " * i)

图案6

                              *
                         *  * *  *
                    *  *  *   *  *  *
               *  *  *  *     *  *  *  *
          *  *  *  *  *       *  *  *  *  *
     *  *  *  *  *  *         *  *  *  *  *  *
*  *  *  *  *  *  *           *  *  *  *  *  *  *
     *  *  *  *  *  *         *  *  *  *  *  *
          *  *  *  *  *       *  *  *  *  *
               *  *  *  *     *  *  *  *
                    *  *  *   *  *  *
                         *  * *  *
                              *
Python
for i in range(8):
    print("     " * (7-i) + "*  " * i + "  " * i + "\b" * 5 + "*  " * i)
for i in range(6,0,-1):
    print("     " * (7-i) + "*  " * i + "  " * i + "\b" * 5 + "*  " * i)

图案7

                              *        *
                         *  *        *  *
                    *  *  *        *  *  *
               *  *  *  *        *  *  *  *
          *  *  *  *  *        *  *  *  *  *
     *  *  *  *  *  *        *  *  *  *  *  *
*  *  *  *  *  *  *        *  *  *  *  *  *  *
     *  *  *  *  *  *        *  *  *  *  *  *
          *  *  *  *  *        *  *  *  *  *
               *  *  *  *        *  *  *  *
                    *  *  *        *  *  *
                         *  *        *  *
                              *        *
Python
for i in range(8):
    print("     " * (7-i) + "*  " * i + "  " * 3 + "*  " * i)
for i in range(6,0,-1):
    print("     " * (7-i) + "*  " * i + "  " * 3 + "*  " * i)

图案8

                               *                                  *
                         *  *                               *  *
                    *  *  *                            *  *  *
               *  *  *  *                         *  *  *  *
          *  *  *  *  *                      *  *  *  *  *
     *  *  *  *  *  *                   *  *  *  *  *  *
*  *  *  *  *  *  *                *  *  *  *  *  *  *
     *  *  *  *  *  *                   *  *  *  *  *  *
          *  *  *  *  *                      *  *  *  *  *
               *  *  *  *                         *  *  *  *
                    *  *  *                            *  *  *
                         *  *                               *  *
                              *                                  *
Python
for i in range(8):
    print("     " * (7-i) + "*  " * i + '  ' * i + "     " * (7-i) + "*  " * i)
for i in range(6,0,-1):
    print("     " * (7-i) + "*  " * i + '  ' * i + "     " * (7-i) + "*  " * i)

图案9

再水一个经典的 9 9乘法口诀表吧:

1 * 1 = 1

1 * 2 = 2 2 * 2 = 4

1 * 3 = 3 2 * 3 = 6 3 * 3 = 9

1 * 4 = 4 2 * 4 = 8 3 * 4 = 12 4 * 4 = 16

1 * 5 = 5 2 * 5 = 10 3 * 5 = 15 4 * 5 = 20 5 * 5 = 25

1 * 6 = 6 2 * 6 = 12 3 * 6 = 18 4 * 6 = 24 5 * 6 = 30 6 * 6 = 36

1 * 7 = 7 2 * 7 = 14 3 * 7 = 21 4 * 7 = 28 5 * 7 = 35 6 * 7 = 42 7 * 7 = 49

1 * 8 = 8 2 * 8 = 16 3 * 8 = 24 4 * 8 = 32 5 * 8 = 40 6 * 8 = 48 7 * 8 = 56 8 * 8 = 64

1 * 9 = 9 2 * 9 = 18 3 * 9 = 27 4 * 9 = 36 5 * 9 = 45 6 * 9 = 54 7 * 9 = 63 8 * 9 = 72 9 * 9 = 81

Python
for x in range(10):
for y in range(1,x+1):
print("%d * %d = %d" %(y,x,y*x),end="\t")
print("\n")

图案10

                                                           * *
                                                        * * * *
                                                     * * * * * *
                                                  * * * * * * * *
                                               * * * * * * * * * *
                                            * * * * * * * * * * * *
                                             * * * * * * * * * * * *
                                              * * * * * * * * * * * *
                                     * *       * * * * * * * * * * * *
                                  * * * *       * * * * * * * * * * * *
                               * * * * * *       * * * * * * * * * * * *
                            * * * * * * * *       * * * * * * * * * * * *
                         * * * * * * * * * *       * * * * * * * * * * * *
                      * * * * * * * * * * * *       * * * * * * * * * * * *
                       * * * * * * * * * * * *       * * * * * * * * * * * *
                        * * * * * * * * * * * *       * * * * * * * * * * * *
               * *       * * * * * * * * * * * *       * * * * * * * * * * * *
            * * * *       * * * * * * * * * * * *       * * * * * * * * * * * *
         * * * * * *       * * * * * * * * * * * *       * * * * * * * * * * * *
      * * * * * * * *       * * * * * * * * * * * *       * * * * * * * * * * * *
   * * * * * * * * * *       * * * * * * * * * * * *       * * * * * * * * * * * *
* * * * * * * * * * * *       * * * * * * * * * * * *       * * * * * * * * * * * *
 * * * * * * * * * * * *       * * * * * * * * * * * *       * * * * * * * * * * * *
  * * * * * * * * * * * *       * * * * * * * * * * * *       * * * * * * * * * * * *
Python
for i in range(1,7):
    print(" " * 3 * (6 - i) + " " * 44 + "* " * i * 2)

for i in range(1,3):
print(" " i + " " 44 + "* " 6 2)

for i in range(1,7):
print(" " 3 (6 - i) + " " 22 + " " i 2 + " " 6 + " " 6 2)

for i in range(1,3):
print(" " i + " " 22 + "* " 6 2 + " " 6 + " " 6 2)

for i in range(1,7):
print(" " 3 (6 - i) + "* " i 2 + " " 6 + " " 6 2 + " " 6 + " " 6 2)

for i in range(1,3):
print(" " i + " " 6 2 + " " 6 + " " 6 2 + " " 6 + " " 6 2)

基本上完成这个adidas的logo后 其他类似的图案基本上可以直接秒了,有兴趣的同学可以尝试独立去完成这个Logo,放一个最终的效果图吧:

转自:https://www.sqlsec.com/2019/11/pyfor.html
作者:国光

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值