打法一:
for i in range(1,10):
for j in range(1,10):
if i <= j:
if j != 9:
if j <= 3:
print('{0}*{1}={2:<1} '.format(i,j,i*j),end='')
else:
print('{0}*{1}={2:<2} '.format(i,j,i*j),end='')
else:
print('{0}*{1}={2:<2} '.format(i,j,i*j))
else:
if j <= 3:
print('{0} {1} {2:<1} '.format(' ',' ',' '),end='')
else:
print('{0} {1} {2:<2} '.format(' ',' ',' '),end='')
运行结果:
1*1=1 1*2=2 1*3=3 1*4=4 1*5=5 1*6=6 1*7=7 1*8=8 1*9=9
2*2=4 2*3=6 2*4=8 2*5=10 2*6=12 2*7=14 2*8=16 2*9=18