菜鸟教程 -- 学的不仅是技术,更是梦想!

Python 3 教程
Python3 教程 Python3 简介 Python3 环境搭建 Python3 VScode Python3 基础语法 Python3 基本数据类型 Python3 数据类型转换 Python3 解释器 Python3 注释 Python3 运算符 Python3 数字(Number) Python3 字符串 Python3 列表 Python3 元组 Python3 字典 Python3 集合 Python3 条件控制 Python3 循环语句 Python3 编程第一步 Python3 推导式 Python3 迭代器与生成器 Python3 with Python3 函数 Python3 lambda Python3 装饰器 Python3 数据结构 Python3 模块 Python __name__ Python3 输入和输出 Python3 File Python3 OS Python3 错误和异常 Python3 面向对象 Python3 命名空间/作用域 Python 虚拟环境的创建 Python 类型注解 Python3 标准库概览 Python3 实例 Python 测验

Python3 高级教程

Python3 正则表达式 Python3 CGI编程 Python3 MySQL(mysql-connector) Python3 MySQL(PyMySQL) Python3 网络编程 Python3 SMTP发送邮件 Python3 多线程 Python3 XML 解析 Python3 JSON Python3 日期和时间 Python3 内置函数 Python3 MongoDB Python3 urllib Python uWSGI 安装配置 Python3 pip Python3 operator Python math Python requests Python random Python OpenAI Python 有用的资源 Python AI 绘画 Python statistics Python hashlib Python 量化 Python pyecharts Python selenium 库 Python 爬虫 Python Scrapy 库 Python Markdown Python sys 模块 Python Pickle 模块 Python subprocess 模块 Python queue 模块 Python StringIO 模块 Python logging 模块 Python datetime 模块 Python re 模块 Python csv 模块 Python threading 模块 Python asyncio 模块 Python PyQt Python for 循环 Python while 循环
(追記) (追記ここまで)

Python 九九乘法表

Document 对象参考手册 Python3 实例

以下实例演示了如何实现九九乘法表:

实例

# -*- coding: UTF-8 -*-# Filename : test.py# author by : www.runoob.com# 九九乘法表foriinrange(1, 10): forjinrange(1, i+1): print('{}x{}={}\t'.format(j, i, i*j), end='')print()

执行以上代码输出结果为:

1x1=1  
1x2=2  2x2=4  
1x3=3  2x3=6  3x3=9  
1x4=4  2x4=8  3x4=12  4x4=16  
1x5=5  2x5=10  3x5=15  4x5=20  5x5=25  
1x6=6  2x6=12  3x6=18  4x6=24  5x6=30  6x6=36  
1x7=7  2x7=14  3x7=21  4x7=28  5x7=35  6x7=42  7x7=49  
1x8=8  2x8=16  3x8=24  4x8=32  5x8=40  6x8=48  7x8=56  8x8=64  
1x9=9  2x9=18  3x9=27  4x9=36  5x9=45  6x9=54  7x9=63  8x9=72  9x9=81

通过指定end参数的值,可以取消在末尾输出回车符,实现不换行。

Document 对象参考手册 Python3 实例

AI 思考中...

7 篇笔记 写笔记

  1. #0

    inernoro

    ine***[email protected]

    5

    乘法表左边的数要比右边的小,如下实例:

    #!/usr/bin/python3
    class multiplicationTable():
     def paint(self,n=9): 
     for row in range(1,n+1): 
     for col in range(1,row+1):
     print("{1}x{0}={2}\t".format(row , col , row*col),end='')
     print();
    table = multiplicationTable()
    table.paint()
    #table.paint(10) #打印 "10x10" 的乘法表
    

    inernoro

    ine***[email protected]

    9年前 (2017年05月31日)
  2. #0

    TwoIceBing

    139***[email protected]

    18
    # 九九乘法表
    for i in range(1, 10):
     for j in range(1, i + 1):
     if i == j:
     print('{1}×{0}={2}'.format(i, j, i * j))
     else:
     print('{1}×{0}={2}'.format(i, j, i * j), end='\t')

    这样写可以有效去除每一行的最后一个空格,输出如下:

    TwoIceBing

    139***[email protected]

    9年前 (2017年12月07日)
  3. #0

    姬无命

    305***[email protected]

    80

    一句话输出99乘法表,可以参考一下:

    print('\n'.join(' '.join("%dx%d=%-2d" % (x, y, x*y) for x in range(1, y+1)) for y in range(1, 10)))

    姬无命

    305***[email protected]

    9年前 (2018年02月07日)
  4. #0

    Jim

    wel***[email protected]

    16

    参考:

    for i in range(1,10):
     for j in range(1,i):
     print "%dx%d=%d" % (j,i,j*i),
     print

    Jim

    wel***[email protected]

    8年前 (2018年05月08日)
  5. #0

    xjsnight

    267***[email protected]

    12
    用列表生成器打印九九乘法表:
    >>> print '\n'.join(['\t'.join(['%d * %d = %d'%(y,x,x*y) for y in range(1,x+1)])for x in range(1,10)])
    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

    xjsnight

    267***[email protected]

    8年前 (2018年05月08日)
  6. #0

    门外汉

    906***[email protected]

    107

    分享给像我这种门外汉,稍微好理解一些,Python3 支持中文变量真好。

    for 行 in range(1,10):
     for 列 in range(1,行+1): # 内循环中,确保列 <= 行。
     print("{}*{}={}\t".format(列,行,列*行),end="") # 确保同一行内容连续
     print() # 另起一行!!!
    input() # 防止程序一闪而过,不在编译器中也能使用

    门外汉

    906***[email protected]

    8年前 (2018年06月13日)
  7. #0

    天青色

    176***[email protected]

    8

    在别的地方看到的一行代码实现九九乘法表,感觉很有意思,就放出来吧。

    print('\n'.join([" ".join([f'{j}*{i}={i * j}' for j in range(1, i + 1)]) for i in range(1, 10)]))

    天青色

    176***[email protected]

    4年前 (2022年08月22日)

点我分享笔记

  • 昵称 (必填)
  • 邮箱 (必填)
  • 引用地址

AltStyle によって変換されたページ (->オリジナル) /