方向一

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. Could not load file or assembly system.data.sqlite.dll or one for it's depedencies

    最近做一个winform项目,因为数据库用的表很少,所以用的是轻量级数据库sqlite.sqlite的优点很多,但是他要分两个版本,32位或者64位,不能同时兼容. 我遇到的问题是,我在开发端用的是. ...

  2. MongoDB的使用学习之(三)安装MongoDB以及一些基础操作

    原文链接:http://www.cnblogs.com/huangxincheng/archive/2012/02/18/2356595.html 此博主的 8天学通MongoDB 系列还是不错的,本 ...

  3. mysql 导出表中数据为excel的xls格式文件

    需求: 利用mysql客户端导出数据库中数据,以便进行分析,统计. 解决命令: 在windos命令行(linux同理)下,用如下命令即可: mysql -hlocalhost -uroot -ppas ...

  4. amqp 抓包 不要在同一台机器

  5. window环境下mysql导入sql文件时报错:ERROR: ASCII '\0' appeared in the statement

    错误信息: ERROR: ASCII '\0' appeared in the statement, but this is not allowed unless option --binary-mo ...

  6. nginx-博客阅读笔记记录-20190916

    Nginx 入门学习教程 Ng官网解释: nginx [engine x]是最初由Igor Sysoev编写的HTTP和反向代理服务器,邮件代理服务器和通用TCP / UDP代理服务器. 维基百科解释 ...

  7. 阿里云ECS无法通过SSL远程链接问题。

    自己配置的SSL,通过密码,公司的是通过密钥,结果也是一样, 环境:centos7.x 网络: 家里宽带 公司网络 省图书馆wifi 家里宽带,公司网络均可以链接上去, 但唯独省图书馆wifi链接失败 ...

  8. mysql order by 自定义

    TIMESTAMPDIFF 语法: TIMESTAMPDIFF(interval,datetime_expr1,datetime_expr2). 说明: 返回日期或日期时间表达式datetime_ex ...

  9. [POJ 1911] 棋盘

    问题描述 将一个8*8的棋盘进行如下分割:将原棋盘割下一块矩形棋盘并使剩下部分也是矩形,再将剩下的部分继续如此分割,这样割了(n-1)次后,连同最后剩下的矩形棋盘共有n块矩形棋盘.(每次切割都只能沿着 ...

  10. 对promise的研究1

    通过看阮一峰老师的文章写出来的特此注明 1.Promise 的含义 Promise 是异步编程的一种解决方案,比传统的解决方案——回调函数和事件——更合理和更强大.它由社区最早提出和实现,ES6 将其 ...