方向一

i = 1

while i <= 9:

  j = 1

  while j <= i

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

    j += 1

  print()

  i += 1

思路:先写出列,从一到九,再写出列,每次行=列的时候换行,行数增加一,所以里面的while循环是 j <= i,当行数小于列数时,执行换行代码,进行下一轮的循环,end = ‘’  表示不换行继续往下写

方向一打印结果示例

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

方向二 

i = 1

while i <= 9:

  k = 1

  while k <= 9 - i:

    print('        ',end = ' ')

    k += 1

  j = 1

  while j <= i

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

    j += 1

  print()

  i += 1

思路:方向二相对于方向一,需要在前面打印空格,且每次打印的空格跟行数有关,这时就需要一个循环,使得前面的空格被打印出来

方向一打印结果示例

                              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

方向三

i = 9

while i >= 1:

  j = 1

  while j <= i

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

    j += 1

  print()

  i -= 1

思路:方向三中的i是从9到1,然后再是把i一个一个往下减

方向三打印结果示例

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
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*7 = 7 2*7 =14 3*7 =21 4*7 =28 5*7 =35 6*7 =42 7*7 =49
1*6 = 6 2*6 =12 3*6 =18 4*6 =24 5*6 =30 6*6 =36
1*5 = 5 2*5 =10 3*5 =15 4*5 =20 5*5 =25
1*4 = 4 2*4 = 8 3*4 =12 4*4 =16
1*3 = 3 2*3 = 6 3*3 = 9
1*2 = 2 2*2 = 4
1*1 = 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'%( j,i ,i*j),end='')

    j += 1

  print()

  i -= 1

思路:和方向二类似,在方向三的基础上,在前面根据行数打印一定量的空格就可以了

方向四打印结果示例

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
             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*7 = 7 2*7 =14 3*7 =21 4*7 =28 5*7 =35 6*7 =42 7*7 =49
                                        1*6 = 6 2*6 =12 3*6 =18 4*6 =24 5*6 =30 6*6 =36
                                                     1*5 = 5 2*5 =10 3*5 =15 4*5 =20 5*5 =25
                                                                   1*4 = 4 2*4 = 8 3*4 =12 4*4 =16
                                                                                 1*3 = 3 2*3 = 6 3*3 = 9
                                                                                              1*2 = 2 2*2 = 4
                                                                                                          1*1 = 1

python while 循环打印九九乘法表的更多相关文章

  1. 写一个方法,用一个for循环打印九九乘法表

    public class MultiplicationTable { /**  * @description 写一个方法,用一个for循环打印九九乘法表   * @author  wangkun  * ...

  2. Java-for循环打印九九乘法表

    Java打印九九乘法表 public class forDemo04 { public static void main(String[] args) { //练习3:打印九九乘法表 /* 1*1=1 ...

  3. for循环打印九九乘法表

    学习目标: 熟练掌握 for 循环的使用 例题: 需求:打印九九乘法表 代码如下: // 九九乘法表 // row 为行,col为列 for(int row = 1; row < 10; row ...

  4. python脚本7_打印九九乘法表

    #打印九九乘法表 for i in range(1,10): s = "" for j in range(1,i+1): s += str(j) + '*' + str(i) + ...

  5. 用JS的for循环打印九九乘法表

    需要使用两个for循环嵌套,代码如下: <!DOCTYPE html> <html lang="en"> <head> <meta cha ...

  6. lua学习之循环打印九九乘法表

    --第4题 输出99乘法表 function PrintMulitiplyTable() , do local res = {} local str = "" , i do res ...

  7. python3:使用for循环打印九九乘法表

    for i in range(1, 10): for j in range(1, i + 1): print(j, '*', i, '=', i * j, end=" ") #en ...

  8. 用for循环打印九九乘法表(for嵌套循环)

    package com.Summer_0416.cn; /** * @author Summer * */ public class Test_Method10 { public static voi ...

  9. JavaScript-双层for循环打印九九乘法表

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

随机推荐

  1. HDU-3665 Seaside

    XiaoY is living in a big city, there are N towns in it and some towns near the sea. All these towns ...

  2. 将图片地址转为blob格式的例子

    HTML代码: <div id="forAppend" class="demo"></div> Javascript代码: <sc ...

  3. 搜索(DFS)---好友关系的连通分量数目

    好友关系的连通分量数目 547. Friend Circles (Medium) Input: [[1,1,0], [1,1,0], [0,0,1]] Output: 2 Explanation:Th ...

  4. openSSH学习笔记(一)

    OpenSSH 是 SSH (Secure SHell) 协议的免费开源实现.SSH协议族可以用来进行远程控制, 或在计算机之间传送文件.而实现此功能的传统方式,如telnet(终端仿真协议). rc ...

  5. 20191125PHP抽象类、接口和魔术方法

    抽象类 不能被实例化,用于其他类的继承.使用abstract(抽象).抽象方法一定是抽象类,抽象类不一定有抽象方法. 接口interface是特殊的抽象类. eg: <?php //抽象类 ab ...

  6. 剑指offer--字符串

    C/C++中每个字符串都以字符'\0'作为结尾,这样我们就可以很方便的找到字符串最后的尾部.由于这个特点,每个字符串中都有一个额外字符的开销,稍不留神就会造成字符串的越界. 为了节省内存,C/C++把 ...

  7. python基础篇(完整版)

    目录 计算机基础之编程和计算机组成 什么是编程语言 什么是编程 为什么要编程 编程语言的分类 机器语言(低级语言) 汇编语言 高级语言 计算机的五大组成 CPU(相当于人类的大脑) 多核CPU(多个大 ...

  8. vue回到顶部

    backTop() { var top = document.body.scrollTop || document.documentElement.scrollTop; this.duration - ...

  9. 2018-8-10-sublime-Text-正则替换

    title author date CreateTime categories sublime Text 正则替换 lindexi 2018-08-10 19:16:52 +0800 2018-2-1 ...

  10. 1145. Hashing - Average Search Time (25)

    The task of this problem is simple: insert a sequence of distinct positive integers into a hash tabl ...