用python打印99乘法口诀表
- 代码如下
#!/usr/bin/env python
# encoding: utf-8
__author__ = 'Nicholas.Cage'
i = 1
j = 1
while i <= 9:
j = 1
while j <= i:
print "%s * %s = %s\t" % (i, j, i*j),
j += 1
i += 1
print
print
for i in range(1, 10):
for j in range(1, i+1):
print "%s * %s = %s\t" % (i, j, i*j),
print
print
i = 9
while i >= 1:
j = 1
while j <= i:
print("%s * %s = %s\t" % (i, j, i*j)),
j += 1
i -= 1
print
print
for i in range(9, 0, -1):
for j in range(i, 0, -1):
print "%s * %s = %s\t" % (i, j, i*j),
print
- 运行结果如下
ssh://root@192.168.109.200:22/root/.pyenv/shims/python -u /root/var/tmp/apepy/Review/2_multi_nine_nine.py
1 * 1 = 1
2 * 1 = 2 2 * 2 = 4
3 * 1 = 3 3 * 2 = 6 3 * 3 = 9
4 * 1 = 4 4 * 2 = 8 4 * 3 = 12 4 * 4 = 16
5 * 1 = 5 5 * 2 = 10 5 * 3 = 15 5 * 4 = 20 5 * 5 = 25
6 * 1 = 6 6 * 2 = 12 6 * 3 = 18 6 * 4 = 24 6 * 5 = 30 6 * 6 = 36
7 * 1 = 7 7 * 2 = 14 7 * 3 = 21 7 * 4 = 28 7 * 5 = 35 7 * 6 = 42 7 * 7 = 49
8 * 1 = 8 8 * 2 = 16 8 * 3 = 24 8 * 4 = 32 8 * 5 = 40 8 * 6 = 48 8 * 7 = 56 8 * 8 = 64
9 * 1 = 9 9 * 2 = 18 9 * 3 = 27 9 * 4 = 36 9 * 5 = 45 9 * 6 = 54 9 * 7 = 63 9 * 8 = 72 9 * 9 = 81
1 * 1 = 1
2 * 1 = 2 2 * 2 = 4
3 * 1 = 3 3 * 2 = 6 3 * 3 = 9
4 * 1 = 4 4 * 2 = 8 4 * 3 = 12 4 * 4 = 16
5 * 1 = 5 5 * 2 = 10 5 * 3 = 15 5 * 4 = 20 5 * 5 = 25
6 * 1 = 6 6 * 2 = 12 6 * 3 = 18 6 * 4 = 24 6 * 5 = 30 6 * 6 = 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* 2 = 10 5 * 1 = 5
4 * 4 = 16 4 * 3 = 12 4 * 2 = 8 4 * 1 = 4
3 * 3 = 9 3 * 2 = 6 3 * 1 = 3
2 * 2 = 4 2 * 1 = 2
1 * 1 = 1
Process finished with exit code 0
用python打印99乘法口诀表的更多相关文章
- Python 打印99乘法口诀表
import string for x in xrange(1,10): for y in xrange(1,x+1): print string.ljust("%d*%d = " ...
- Java 面试 - 打印九九乘法口诀表
在Java面试过程中, 面试者经常会被要求手写代码或上机操作.一般来说,手写代码或上机操作,主要还是考察面试者的分析问题和解决问题的能力.打印九九乘法口诀无疑是非常基础的,那么如何实现呢?首先我们先来 ...
- java 打印出99乘法口诀表
public class Mutiplay { /** *实现99乘法表 * @param args */ public static void main(String[] args) { Syste ...
- print函数详解及python打印99乘法表的不同方法
首先你需要了解print的原型,并且要知道在python2和python3中print函数功能不同,不只是表现在后面带不带()一方面! 在python3中,通过help(print)可以得到print ...
- python打印99乘法表
代码如下: print(XXX,end="\t") #表示打印不换行 附带python部分转义字符:
- 如何利用while语句打印“九九乘法口诀表”
需求:输出九九乘法表 plus.py代码如下: i=1 j=1 while i<=9: j=1 while j<=i: print(j,'*',i,'=',str(i*j)+' ',end ...
- python 9*9乘法口诀表
# -*- coding: utf-8 -*- # __author__ = 'Carry' for i in range(1, 10): for j in range(1, i + 1): prin ...
- python3 打印九九乘法口诀表
for i in range(1, 10): for j in range(1, i+1): # print(f'{i}×{j}={i*j}', end='\t') print('%d×%d=%d' ...
- scala 打印一个乘法口诀表 (<<scala 编程>> P87)
(for(i <- 1 to 9;j <- 1 to i; s = s"$j*$i=${i*j}\t") yield {if(j==1) s"$s\n&quo ...
随机推荐
- 160512、nginx+多个tomcat集群+session共享(windows版)
第一步:下载nginx的windows版本,解压即可使用,点击nginx.exe启动nginx 或cmd命令 1.启动: D:\nginx+tomcat\nginx-1.9.3>start ng ...
- 【Python之路】Python目录
Python基础1 -- Python由来.Python种类.编码方式, Python基础2 -- Python运算符.数据类型.enumerate.range.for循环 python基础3 -- ...
- llvm,gcc
GCC,LLVM,Clang编译器对比 在XCode中,我们经常会看到这些编译选项(如下图),有些人可能会有些茫然,本文将对GCC4.2.LLVM GCC 4.2.LLVM compliler 2 ...
- ES6中的let和const
let和const let 用来声明变量,但是所声明的变量只在let命令所在的代码块内有效 { let a=12 alert(a)//12 } alert(a)//报错 找不到 let不像var那样会 ...
- HBase-MR
一.需求1:对一张表的rowkey进行计数 官方HBase-Mapreduce 需求1:对一张表的rowkey进行计数 1)导入环境变量 export HBASE_HOME=/root/hd/hbas ...
- js小数四舍五入,保留两位小数
直接用用number.toFixed(2)即可 <template> <section class="p-10"> <h1> {{ number ...
- Python 中的匿名函数,你滥用了吗?
概念 我们从一个例子引入. 这里有一个元素为非空字符串的列表,按字符串最后一个字母将列表进行排序.如果原列表是 ['abc', 'g', 'def'],则结果应该是 ['abc', 'def', 'g ...
- <Android 开源库> GreenDAO 使用方法具体解释<译文>
简单介绍 greenDAO是一个开源的Android ORM,使SQLite数据库的开发再次变得有趣. 它减轻了开发者处理底层的数据库需求,同一时候节省开发时间. SQLite是一个非常不错的关系型数 ...
- PAT 1140 Look-and-say Sequence [比较]
1140 Look-and-say Sequence (20 分) Look-and-say sequence is a sequence of integers as the following: ...
- windows批处理初学贴出一些命令
在cmd窗口中复制时,右键选标记,然后再选择此时选择区域就变白了.然后要么直接拖到要粘贴的地方,要么直接按回车存到剪贴板里. 1.循环导入文件夹下面的文件到数据库中 cd /d D:/Program ...