zoukankan      html  css  js  c++  java
  • Python写出的九九乘法表(while循环)

    while循环的的四种方向的九九乘法表

    #方向一

     

    i = 1
    while i <= 9:
        j = 1
        while j <= i:
            print("%d*%d=%-2d"%(i,j,i*j),end = ' ')  # %d: 整数的占位符,'-2'代表靠左对齐,两个占位符
            j += 1
        print()
        i += 1

     #下图为以上代码运行结果

     #方向二

    i = 1

    while i <= 9:

        k = 1

        while k <= 9 - i:         #判断应该用多少个空格来填充前面的空白

            print('       ',end = '')

            k += 1

        j = 1

        while j <= i:

            print("%d*%d=%-2d"%(i,j,i*j),end = ' ')

            j += 1

        print()

        i += 1

      #下图为以上代码运行结果

     #方向三

    i = 9

    while i >= 1:

        j = 1

        while j <= i:

            print("%d*%d=%2d"%(i,j,i*j),end = ' ')

            j += 1

        print()

        i -= 1

      #下图为以上代码运行结果

     #方向四

    i = 9

    while i >= 1:

        k = 1

        while k <= 9-i:

            print('       ',end = '')

            k += 1

        j = 1

        while j<= i:

            print("%d*%d=%2d"%(i,j,i*j),end = ' ')

            j += 1

        print()

        i -= 1

       #下图为以上代码运行结果

     


    以上要是有什么不规范的地方希望大神们多多指点

  • 相关阅读:
    AQS简介
    原子类案例
    保证线程安全的三个方面
    CAS无锁机制
    乐观锁与悲观锁
    读写锁简介
    重入锁简介
    并发队列Queue
    报错Cannot resolve com.mysq.jdbc.Connection.ping method. Will use 'SELECT 1' instead 问题记录
    Springboot中MyBatis 自动转换 map-underscore-to-camel-case
  • 原文地址:https://www.cnblogs.com/anzai/p/7860248.html
Copyright © 2011-2022 走看看