#!/usr/bin/python
#用Python实现九九乘法表(9*9 乘法口诀表)
#分行与列考虑,共9行9列,i控制行,j控制列
#方法一采用for循环
#后面的方法采用函数和for循环结合
print (
"====================方法一===================="
)
for
i
in
range(1, 10):
for
j
in
range(1,i+1):
d=i*j
print(
'%d*%d=%-2d'
%(i,j,d),end=
' '
)
print ()
print (
"====================方法二===================="
)
def hwb(n):
m=n
sums=0
for
j
in
range(1, n+1):
sums=m*j
print(
'%d*%d=%-2d'
%(m,j,sums),end=
' '
)
print ()
def hwb1():
for
i
in
range(1,10):
hwb(i)
hwb1()
print (
"====================方法三===================="
)
def hwb(n):
m=n
sums=0
for
j
in
range(1, n+1):
sums=m*j
print(
'%d*%d=%-2d'
%(m,j,sums),end=
' '
)
print()
def hwb2():
for
i
in
range(9,0,-1):
hwb(i)
hwb2()
print (
"====================方法四===================="
)
def hwb(n):
m=n
sums=0
for
k
in
range(0, 9-n):
print(
' '
,end=
''
)
for
j
in
range(1, n+1):
sums=m*j
print(
'%d*%d=%-2d'
%(m,j,sums),end=
' '
)
print()
def hwb3():
for
i
in
range(1,10):
hwb(i)
hwb3()
print (
"====================方法五===================="
)
def hwb(n):
for
dix
in
range(9-n,0,-1):
print(
' '
,end =
''
)
sums = 0
m = n
for
j
in
range(1,n+1):
sums = m*j
print(
"%d*%d=%-2d"
%(m,j,sums),end =
' '
)
print()
def hwb4():
for
i
in
range(9,0,-1):
hwb(i)
hwb4()