# ##1、正三角1 x 1 = 1for y in range(1,10): ##從1到9共迴圈9次,1次就控制1行
for x in range(1,y+1): ###控制當前公式的計算和列印次數
print("%d x %d = %d"%(x,y,x*y),end="\t") ##公式和公式之間 空格,\t的作用是保持上下對齊但是不換行
print() ##一行結束,預設print()換行
##2、倒三角
for y in range(-9,0): ##從-9到-1共迴圈9次,1次控制1行
for x in range(1,-y+1): ###控制當前公式的計算和列印次數
print("%d x %d = %d"%(x,-y,x*(-y)),end="\t") ##公式和公式之間 空格,但是不換行
print() ##一行結束,預設print()換行
執行結果:
1、正三角
1 x 2 = 2 2 x 2 = 4
1 x 3 = 3 2 x 3 = 6 3 x 3 = 9
1 x 4 = 4 2 x 4 = 8 3 x 4 = 12 4 x 4 = 16
1 x 5 = 5 2 x 5 = 10 3 x 5 = 15 4 x 5 = 20 5 x 5 = 25
1 x 6 = 6 2 x 6 = 12 3 x 6 = 18 4 x 6 = 24 5 x 6 = 30 6 x 6 = 36
1 x 7 = 7 2 x 7 = 14 3 x 7 = 21 4 x 7 = 28 5 x 7 = 35 6 x 7 = 42 7 x 7 = 49
1 x 8 = 8 2 x 8 = 16 3 x 8 = 24 4 x 8 = 32 5 x 8 = 40 6 x 8 = 48 7 x 8 = 56 8 x 8 = 64
1 x 9 = 9 2 x 9 = 18 3 x 9 = 27 4 x 9 = 36 5 x 9 = 45 6 x 9 = 54 7 x 9 = 63 8 x 9 = 72 9 x 9 = 81
2、倒三角
1 x 9 = 9 2 x 9 = 18 3 x 9 = 27 4 x 9 = 36 5 x 9 = 45 6 x 9 = 54 7 x 9 = 63 8 x 9 = 72 9 x 9 = 81
1 x 8 = 8 2 x 8 = 16 3 x 8 = 24 4 x 8 = 32 5 x 8 = 40 6 x 8 = 48 7 x 8 = 56 8 x 8 = 64
1 x 7 = 7 2 x 7 = 14 3 x 7 = 21 4 x 7 = 28 5 x 7 = 35 6 x 7 = 42 7 x 7 = 49
1 x 6 = 6 2 x 6 = 12 3 x 6 = 18 4 x 6 = 24 5 x 6 = 30 6 x 6 = 36
1 x 5 = 5 2 x 5 = 10 3 x 5 = 15 4 x 5 = 20 5 x 5 = 25
1 x 4 = 4 2 x 4 = 8 3 x 4 = 12 4 x 4 = 16
1 x 3 = 3 2 x 3 = 6 3 x 3 = 9
1 x 2 = 2 2 x 2 = 4
1 x 1 = 1
python實現九九乘法表
規律 1.列數隨著行數的變化而變化 2.列數的最大值和行數相等 3.列印9行,行的取值範圍為1 9 4.列的取值範圍 1 行數 line 1 行 外層迴圈控制 while line 9 colum 1 列 內層迴圈控制,沒列印一行,需要重置列的值 while colum line print dx ...
python九九乘法表
之前愛人用excel寫了九九乘法表 if and column a1 row a1 row a1 10 column a1 row a1 column a1 row a1 試試用python寫乙個九九乘法表。重構a a乘法表 函式 def jjcfb a for i in range 1,a 1 f...
Python 九九乘法表
以下例項演示了如何實現九九乘法表 coding utf 8 filename test.py author by www.runoob.com 九九乘法表 通過指定end引數的值,可以取消在末尾輸出回車符,實現不換行。for i in range 1 10 for j in range 1 i 1 ...