#循环输出99乘法表 
i=1 while i <=9: c=1 while c <=i: print("{}*{}={:2}".format(c,i, i * c), end=' ') c+=1 print(" ") i+=1

 

以下为各种类型的花式变化,可自行拓展

i=1
while i <=9:
    c=1
    while c <=i:
        print("{}*{}={:2}".format(c,i, i * c), end='    ')
        c+=1
    print(" ")
    i+=1
print(" ")

i=9
while i >=1:
    c = 1
    while c <=i:
        print("{}*{}={:2}".format(c,i, i * c), end='    ')
        c+=1
    print(" ")
    i-=1

i=1
while i <=9:
    print('          ' * (9 - i), end='')
    c=1
    while c <=i:
        print("{}*{}={:2}".format(c,i, i * c), end='    ')
        c+=1
    print(" ")
    i+=1
print(" ")

i=9
while i >=1:
    print('          ' * (9 - i), end='')
    c=1
    while c <=i:
        print("{}*{}={:2}".format(c,i, i * c), end='    ')
        c+=1
    print(" ")
    i-=1

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

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



for i in range(1, 10):
    print('          ' * (9 - i), end='')
    for c in range(1, i + 1):
        print("{}*{}={:2}".format(c, i, i * c), end='    ')
    print("     ")
print(" ")

for i in range(9, 0, -1):
    print('          ' * (9 - i), end='')
    for c in range(1, i + 1):
        print("{}*{}={:2}".format(c, i, i * c), end='    ')
    print("     ")
View Code

 

posted on 2019-11-27 17:50  海砂砾  阅读(108)  评论(0)    收藏  举报