博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python九九乘法表(详解)
阅读量:4098 次
发布时间:2019-05-25

本文共 561 字,大约阅读时间需要 1 分钟。

一、第一种for实现(不推荐)

在这里插入图片描述

代码:

for j in range(1, 10):      #计从1到9,不包括10,而且1-9是连续的range(100)默认0-99    for i in range(1, j+1): #观察发现乘号左边的数字小于等于右边的数字,i左,j右,一般二层循环的变量小于一层的(非通用)        result = i * j        if i 

参考原博客链接:

(2)第二种for实现

在这里插入图片描述

代码:

for row in range(1, 10):    for col in range(1, row+1):        print('{}*{}={}'.format(col, row, col * row), end='\t')    print()

二、while实现

在这里插入图片描述

代码:

用while实现

row = 1while row <10:    col = 1    while col <= row:        print('{}*{}={}'.format(col, row, col * row), end = '\t')#见for循环的分析        col += 1    print()   #换行    row += 1  #内循环结束,外循环加一

转载地址:http://mkwsi.baihongyu.com/

你可能感兴趣的文章
Koa2框架原理解析和实现
查看>>
C++模板
查看>>
【C#】如何实现一个迭代器
查看>>
【C#】利用Conditional属性完成编译忽略
查看>>
【Unity】微信登录后将头像存为bytes,将bytes读取成sprite图片
查看>>
【Unity】使用GPS定位经纬度
查看>>
最小费用流 Bellman-Ford与Dijkstra 模板
查看>>
mapReduce(3)---入门示例WordCount
查看>>
hbase(3)---shell操作
查看>>
hbase(1)---概述
查看>>
hbase(5)---API示例
查看>>
SSM-CRUD(1)---环境搭建
查看>>
Nginx(2)---安装与启动
查看>>
springBoot(5)---整合servlet、Filter、Listener
查看>>
C++ 模板类型参数
查看>>
C++ 非类型模版参数
查看>>
DirectX11 光照
查看>>
图形学 图形渲染管线
查看>>
DirectX11 计时和动画
查看>>
DirectX11 光照与材质的相互作用
查看>>