python两则99乘法表
分别应用while和for的嵌套循环,适用于初学的人看看
x = 1
while x <= 9:
y = 1
while y <= x:
print (y,'*',x,'=',x*y,end="\t")
y += 1
print ("")
x += 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
for i in range(1,10):
for j in range(1,1+i):
print ("%dx%d=%d\t"%(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
python两则99乘法表的更多相关文章
- Python之打印99乘法表
本脚本实现打印99乘法表 #!/usr/bin/python #9*9 for i in range(1,10): print for j in range(1,i+1): print "% ...
- js实现两种99乘法表
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- js for和while两种99乘法表
<script type="text/javascript"> for(var i=1; i<=9; i++) { for(var j=1; j<=i;j+ ...
- 用python实现不同格式99乘法表输出
前言:学习python已经有一段时间了,最近发现有时候会出现一个东西知道,也能写出来,但是说不出来的情况.思考后觉得是基础还不够扎实,只一味写代码,没有深入思考具体实现的逻辑,以及各个点之间的关联.所 ...
- python打怪之路【第一篇】:99乘法表
需求:实现99乘法表 代码: #!/usr/bin/env python # -*- coding:utf-8 -*- #author chenjing for i in range(10): for ...
- python的while嵌套 99乘法表 三角形和正方形
python的99乘法表 num1=1 while num1<=9 : num2 = 1 while num2 <=num1 : print (str(num2)+"X" ...
- python之99乘法表
#99乘法表 fir=1 while fir<=9: sec=1 while sec<=fir: print(str(fir)+'*'+str(sec)+'='+str(fir*sec)) ...
- Python 实现99乘法表
首先,我们来回忆一下99乘法表长什么样子吧 进入正题:实现99乘法表 一.For循环 for i in range(1,10): for j in range(1,i+1): print(" ...
- 打印99乘法表-python
题目:如何打印出阶梯状的99乘法表? 题解: #coding:utf-8def multiplication_tables(num):#for i in range(1,10): for j in r ...
随机推荐
- Qt 图片缩放参数计算
缩放图片 void VCImgWidget::wheelEvent(QWheelEvent *event) { ) { // 当滚轮远离使用者时 //ui->textEdit->zoomI ...
- 【Linux】walle 部署上线单报错:mv: cannot overwrite directory ‘/www’ with non-directory
错误截图 问题分析:项目设置中. 目标集群部署路径错误, 举例: 假设你 项目名称:laofan 在目标服务器的路径: /www/wwwdata/laofan 那么你在标集群部署路径 就可以写: /w ...
- python读取yaml文件,在unittest中使用
python读取yaml文件使用,有两种方式: 1.使用ddt读取 2,使用方法读取ddt的内容,在使用方法中进行调用 1.使用ddt读取 @ddt.ddt class loginTestPage(u ...
- js scheme 打开手机app的方法
1.iframe function schemeUrl(url,callbak){ var ifr = document.createElement("iframe"); ifr. ...
- [LeetCode] 248. Strobogrammatic Number III 对称数III
A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside ...
- [LeetCode] 482. License Key Formatting 注册码格式化
You are given a license key represented as a string S which consists only alphanumeric character and ...
- IEDA中使用阿里插件Alibaba Cloud Toolkit和Arthas(阿尔萨斯)
在 IntelliJ IDEA 中安装和配置 Cloud Toolkit 在 IntelliJ IDEA 中安装和配置 Cloud Toolkit 后,您可以将本地应用快速部署到阿里云 ECS.EDA ...
- app内嵌h5页面在ios手机端滑动卡顿的解决方法
1.带滚动条的dom需加样式 -webkit-overflow-scrolling: touch;2.去掉 width:100%; height:100%
- Mechanical Simulation借助UE发力自动驾驶仿真
Source https://www.unrealengine.com/en-US/blog/making-autonomous-vehicles-safer-before-they-hit-the- ...
- [转帖]AMD Zen霄龙中国版:海光x86拿下加解密全球第一
AMD Zen霄龙中国版:海光x86拿下加解密全球第一 http://www.eetop.cn/cpu_soc/6946203.html 其实技术发展都是先模仿 剽窃 再自我创新的 要加以鼓励 总比 ...