用for循环打印九九乘法表:

1
2
3
4
5
6
for in range (1,10):
    for in range(1,10):
        print(j,"x",i,"=",i*j,"\t",end="")
        if i==j:
            print("")
            break

 打印结果是:

1
2
3
4
5
6
7
8
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 

  

while循环打印九九乘法表:

1
2
3
4
5
6
7
8
9
10
11
i=0
j=0
while i<9:
    i+=1
    while j<9:
        j+=1
        print(j,"x",i,"=",i*j,"\t",end="")
        if i==j:
            j=0
            print("")
            break

  

打印结果是:

1
2
3
4
5
6
7
8
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 

用一句话打印九九乘法表:

1
print ('\n'.join([' '.join(['%s*%s=%-2s' % (y,x,x*y) for in range(1,x+1)]) for in range(1,10)]))

打印结果:

1
2
3
4
5
6
7
8
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循环,while循环,一条命令打印99乘法表的更多相关文章

  1. Java流程控制:增强for循环,break&continue,打印99乘法表

    增强for循环:java5引入了一种主要用于数组或集合的增强for循环for(声明语句:表达式){//代码句子} 声明语句:声明新的局部变量,该变量的类型必须和数组元素的类型匹配.其作用域限定在循环语 ...

  2. 使用for循环打印9×9乘法表

    请使用for循环,倒序打印9×9乘法表. 打印结果如下图所示: 使用for循环打印9×9乘法表 #include <stdio.h> int main() { int i, j, resu ...

  3. Python之打印99乘法表

    本脚本实现打印99乘法表 #!/usr/bin/python #9*9 for i in range(1,10): print for j in range(1,i+1): print "% ...

  4. print函数详解及python打印99乘法表的不同方法

    首先你需要了解print的原型,并且要知道在python2和python3中print函数功能不同,不只是表现在后面带不带()一方面! 在python3中,通过help(print)可以得到print ...

  5. python打印99乘法表

    代码如下: print(XXX,end="\t") #表示打印不换行 附带python部分转义字符:

  6. Oracle中打印99乘法表的13种方法

    --实现1: select r1 || '*' || r1 || '=' || r1 * r1 A, decode(r2, '', '', r2 || '*' || r1 || '=' || r2 * ...

  7. 打印99乘法表-python

    题目:如何打印出阶梯状的99乘法表? 题解: #coding:utf-8def multiplication_tables(num):#for i in range(1,10): for j in r ...

  8. python(7)- 小程序练习:循环语句for,while实现99乘法表

    打印99乘法表 for 循环语句实现: for i in range(1,10): for j in range(1,10): print(j,"x",i,"=" ...

  9. For循环练习之99乘法表和转义字符

    之前说了for循环的概念以及常用到的操作,那么我们接下来做几个巩固练习: 1.打印99乘法表: 99乘法表的形式: 1*1 = 1 1*2 = 2 2*2 = 4 1*3 = 3 2*3 = 6 3* ...

随机推荐

  1. e1000

    http://blog.csdn.net/sdulibh/article/details/41826221 http://blog.csdn.net/evenness/article/details/ ...

  2. Linux - 操作系统

    操作系统(科普章节) 目标 了解操作系统及作用 1. 操作系统(Operation System,OS) 操作系统作为接口的示意图 没有安装操作系统的计算机,通常被称为 裸机 如果想在 裸机 上运行自 ...

  3. Educational Codeforces Round 63-D(基础DP)

    题目链接:https://codeforces.com/contest/1155/problem/D 题意:给定n个数,可以选择一段连续子段将其乘x,也可以不操作,求最大连续子段和. 思路:比赛时觉得 ...

  4. Pains and Sickness 学习笔记

    Headaches can be very painful and can last for a long time. If you have a headache, your head hurts. ...

  5. 动态添加 SqlParameter 参数

    List<SqlParameter> paras = new List<SqlParameter>(); paras.Add(new SqlParameter("@m ...

  6. [leetcode]244. Shortest Word Distance II最短单词距离(允许连环call)

    Design a class which receives a list of words in the constructor, and implements a method that takes ...

  7. node.js中express的Router路由的使用

    express中的Router作用就是为了方便我们更好的根据路由去分模块.避免将所有路由都写在入口文件中. 一.简单的使用Router const express = require('express ...

  8. Spring Boot学习笔记:整合Shiro

    Spring Boot如何和Shiro进行整合: 先自定义一个Realm继承AuthorizingRealm,并实现其中的两个方法,分别对应认证doGetAuthenticationInfo和授权do ...

  9. mybatis的resultMap与resultType的区别

    一.概述MyBatis中在查询进行select映射的时候,返回类型可以用resultType,也可以用resultMap,resultType是直接表示返回类型的,而resultMap则是对外部Res ...

  10. Linux下 刚安装完mysql 修改密码

    在Centos中安装MySQL后默认的是没有root密码的,默认的是回车, 那么为了方便需要修改密码. 没有密码为MYSQL加密码: mysql -uroot -p 回车 提示输入密码,为空回车 up ...