libra-gyf

python-乘法表


for i in range(1,10):
    j=1
    while j<=i:
        print('{} * {} = {:2}'.format(j, i, i * j), end="  ")
        j+=1
    print()
        


for i in range(1,10):
    for j in range(1,10):
        if i>=j:
            print('{} * {} = {:2}'.format(i,j,i*j),end=" ")
    print()

 

#for in 方法
for
i in range(1,10): for j in range(i,10): print("%d*%d=%2d" % (j,i,i*j),end=" ") print("")
for i in range(1,10):
    for j in range(9,i-1,-1):
        print("{}*{} ={:<2}".format(i ,j ,i*j),end=' ')
    print()

for i in range(9,0,-1):
    for j in range(i,0,-1):
        print("{}*{} ={:<2}".format(i, j, i * j), end=' ')
    print()

for i in range(1,10):
    for j in range(1,i+1):
        print("{}X{}={:<2}".format(i, j, i * j), end=' ')
    print()

 

#while 方法
i=1
while i < 10:
    j = 1
    while j <=i:
        print("%d*%d=%2d"%(j,i,j*i),end=" ")
        j+=1
    print("")
    i+=1

posted on 2019-12-12 10:14  libra-gyf  阅读(182)  评论(0编辑  收藏  举报

导航